英文:
Not able to filter out a value in jsonPath
问题
I am working on JSONPath where I need to fetch a value for a particular country below is the given JSON.
{
"homeCountry": "USA",
"internationalControlDetails": [
{
"address": {
"city": null,
"country": "Canada",
"county": null,
"state": null,
"zipCode": null
},
"dateRange": {
"endDate": null,
"startDate": null
},
"isHomeCountry": false,
"regionId": null,
"locationControlId": 649289
},
{
"address": {
"city": null,
"country": "United States",
"county": null,
"state": null,
"zipCode": null
},
"dateRange": {
"endDate": null,
"startDate": null
},
"isHomeCountry": true,
"regionId": null,
"locationControlId": 837251
}
],
"locationShieldState": "DISABLED",
"regionControlDetails": []
}
For the given JSON I need to fetch locationControlId
for a particular country.
I have tried
$.internationalControlDetails.[?(@.country == 'Canada')].locationControlId
But it is not working.
I am expecting to fetch locationControlId
for a particular country like Canada, United States
英文:
I am working on JSONPath where I need to fetch a value for a particular country below is the given JSON.
{
"homeCountry": "USA",
"internationalControlDetails": [
{
"address": {
"city": null,
"country": "Canada",
"county": null,
"state": null,
"zipCode": null
},
"dateRange": {
"endDate": null,
"startDate": null
},
"isHomeCountry": false,
"regionId": null,
"locationControlId": 649289
},
{
"address": {
"city": null,
"country": "United States",
"county": null,
"state": null,
"zipCode": null
},
"dateRange": {
"endDate": null,
"startDate": null
},
"isHomeCountry": true,
"regionId": null,
"locationControlId": 837251
}
],
"locationShieldState": "DISABLED",
"regionControlDetails": []
}
For the given JSON I need to fetch locationControlId
for a particular country.
I have tried
$.internationalControlDetails.[?(@.country == 'Canada')].locationControlId
But it is not working.
I am expecting to fetch locationControlId
for a particular country like Canada, United States
答案1
得分: 1
你的路径应该是
$.internationalControlDetails.[?(@.address.country=='Canada')].locationControlId
请注意本地路径中的 `address`。
其他部分看起来是正确的。
英文:
Your path should be
$.internationalControlDetails.[?(@.address.country=='Canada')].locationControlId
Note the address
in the local path.
Everything else looks right.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论