0

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

Akshay G
  • 2,070
  • 1
  • 15
  • 33
Adil Raza
  • 65
  • 6

1 Answers1

1

Your path should be

$.internationalControlDetails.[?(@.address.country=='Canada')].locationControlId

Note the address in the local path.

Everything else looks right.

gregsdennis
  • 7,218
  • 3
  • 38
  • 71