0

I have a json payload that looks like this

{
   "data":{
      "methods":[
         [
            {
               "p_id":"01",
               "description":"Test01",
               "offline":true
            }
         ],
         [
            {
               "p_id":"02",
               "description":"Test02",
               "offline":false
            }
         ],
         [
            {
               "p_id":"03",
               "description":"Test03",
               "offline":true
            }
         ]
      ]
   }
}

How can I write a JSONPath expression to get the "p_id" where "offline"= false?

1 Answer 1

1

You can use a filter expression which selects all elements in an object or array that match the specified filter. For example, [?(@.offline === false)] will match any object if its offline property is strictly false.

So, if the object is always in the same place, you could do:

$.data.methods.*[?(@.offline === false)].p_id

Or, if you want to look for any object where offline is false and fetch p_id, you could use a recursive descent with the filter expression:

$..[?(@.offline === false)].p_id

Note: I used strict equality in my examples so it will only match with a boolean false. If you don't need/want that you could instead simply use a ! to negate the filter. E.g. [?([email protected])]

Sign up to request clarification or add additional context in comments.

Comments

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.