Need a json path expression for below json

旧城冷巷雨未停 提交于 2019-12-14 04:04:10

问题


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"
   }
]

回答1:


Able to resolve this by below expression

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


来源:https://stackoverflow.com/questions/45207907/need-a-json-path-expression-for-below-json

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!