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"
}
]
}
$.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: stackoverflow.com/questions/30030652/…