0

Given a JSON, how do I check if value is present in the list of string.

From the below JSON, I need to check if name1 exists or not. Something like:

$.listToCheck in ['name1']
{
    "firstName": "John",
    "lastName": "doe",
    "age": 26,
    "listToCheck" : [
        "name1", "name2"
    ],
    "address": {
        "streetAddress": "naist street",
        "city": "Nara",
        "postalCode": "630-0192"
    },
    "phoneNumbers": [
        {
            "type": "iPhone",
            "number": "0123-4567-8888"
        },
        {
            "type": "home",
            "number": "0123-4567-8910"
        }
    ]
}
user_pvr
  • 121
  • 1
  • 8
  • What about `$.listToCheck[?(@ == 'name1')]` or `$.listToCheck[?(@.indexOf('name1') != -1)]` I guess it depends what you want to return - it you are just looking for a true/false this will work. If you want to return something else then this is a possible duplicate of: https://stackoverflow.com/questions/30030652/filter-the-json-according-to-string-in-an-array-in-jsonpath – Jerry Jeremiah May 02 '23 at 22:44

0 Answers0