3

How use JMESPath to filter nodes that possess email receivers with exact email? I have JSON object:

   [     
     {
        "test":1,
        "emailReceivers": [
          {
            "emailAddress": "[email protected]",
          }
        ]
      },
      {
        "test":2,
        "emailReceivers": [
          {
            "emailAddress": "[email protected]",
          },
          {
            "emailAddress": "[email protected]",
          }
        ]
      }
    ]

I would like to get node after filtering by elememailReceivers that contains [email protected]:

     {
        "test":1,
        "emailReceivers": [
          {
            "emailAddress": "[email protected]",
          }
        ]
      }

I was trying to use documentation https://jmespath.org/ and examples but I failed.

1 Answer 1

4

You can indeed use contains on a filter and ask sub-keys containing a certain value.

With the query

[?contains(emailReceivers[].emailAddress, '[email protected]')]

This will give:

[
  {
    "test": 1,
    "emailReceivers": [
      {
        "emailAddress": "[email protected]"
      }
    ]
  }
]

On your example array:

[     
  {
    "test":1,
    "emailReceivers": [
      {
        "emailAddress": "[email protected]"
      }
    ]
  },
  {
    "test":2,
    "emailReceivers": [
      {
        "emailAddress": "[email protected]"
      },
      {
        "emailAddress": "[email protected]"
      }
    ]
  }
]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.