0

I have some JSON data from a third-party and I am using JSON Path to transform the data. Below is a sample of the JSON data and the expressions I am trying.

{
  "Traveller": [
    {
      "FirstName": "Passenger",
      "LastName": "One",
      "EmailAddresses": {
        "Email": {
          "EmailAddress": [
            "[email protected]",
            "[email protected]"
          ]
        }
      }      
    },
    {
      "FirstName": "Passenger",
      "LastName": "Two",
      "EmailAddresses": {
        "Email": {
          "EmailAddress": "[email protected]"
        }
      }
    }
  ]
}

I can get the array of email address fine using the following expression:

$..Traveller[*].EmailAddresses.Email.EmailAddress[*]
Returns
[
  "[email protected]",
  "[email protected]"
]

But I require an expression which will return just the "[email protected]".

I have tried the following expressions:

$..Traveller[*].EmailAddresses.Email.EmailAddress.*
$..Traveller[*].EmailAddresses.Email.EmailAddress[2]

I think I need someway of filtering to the EmailAddress where it is NOT an array.

1 Answer 1

1

From all the Traveller:

  • get all whose EmailAddresses.Email.EmailAddress are not array accessible ([?([email protected][0])]);
  • then extract their EmailAddresses.Email.EmailAddress.

All together:

$..Traveller[?([email protected][0])].EmailAddresses.Email.EmailAddress
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.