0

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

1
  • 1
    Jsonpath expression is correct. Use jsonpath.herokuapp.com to test. Commented Jan 16, 2022 at 19:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.