I am using jsonpath library (https://github.com/json-path/JsonPath) in Go, and I need to process a JSON object and filter from an array of objects, the objects which match any of the multiple criteria (OR conditions). I have been unsuccessful in getting the filter to work correctly and hoping that someone can help me in the right direction. I am providing a simplified example below.
Let us assume I have the following JSON Object.
{
"firstName": "John",
"lastName" : "doe",
"age" : 26,
"address" : {
"streetAddress": "naist street",
"city" : "Nara",
"postalCode" : "630-0192"
},
"phoneNumbers": [
{
"type" : "iPhone",
"number": "123-4567-8888"
},
{
"type" : "home",
"number": "123-4567-8910"
},
{
"type" : "mobile",
"number": "123-4567-1233"
}
]
}
I would like filter all phone numbers (phoneNumbers) which are of type "home" or "iPhone". I have used the following expression, but it results in an empty array:
$.phoneNumbers[?(@.type=='home' || @.type == 'iPhone')]
Please see this JSONPath expression tester below. I have saved the JSON here, but it doesn't keep the JSONPath expression, and it will need to be pasted manually. JSONPath Expression Tester