无法在jsonPath中筛选出一个值。

huangapple go评论50阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年4月17日 17:54:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/76033859.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定