Shrikant
Shrikant

Reputation: 126

Need a json path expression for below json

Need a JSON path expression for below JSON. I wanted to extract "Id" for each specific "name"

For Example: I need to extract "Id" : "3" for "name" : "XYZ" .

I tried a JSON path expression as $..Id which given output as:

[
   "1",
   "2",
   "3"
]

But I needed an Id specific to "name": "XYZ"`

[
   {
      "primary":{
         "name":"ABC"
      },
      "Id":"1"
   },
   {
      "primary":{
         "name":"PQR"
      },
      "Id":"2"
   },
   {
      "primary":{
         "name":"XYZ"
      },
      "Id":"3"
   }
]

Upvotes: 0

Views: 144

Answers (1)

Shrikant
Shrikant

Reputation: 126

Able to resolve this by below expression

$..[?(@.primary.name == 'XYZ')].Id

Upvotes: 1

Related Questions