jsonjsonpath

JSONPath filter property by value in object


How can I use the JSONPath filtering capabilities to query for a specific condition on a property on a subobject (without an array)?

Consider this JSON example:

{
  "queue": {
    "size": 13
  }
}

I want to get a match if the .queue.size is greater than 0 and no match if it's equal to 0. I tried using the following query but it does not work: $.queue[?(@.size>0)]. It is unclear to me why is that since the $.queue[size] does work returning value 13 correctly in this example, but if I include the filtering syntax I never get a match.


Solution

  • It looks like JSONPath expressions applies only to arrays. See here and here. Your query $.queue[?(@.size>0)] works for:

    {
      "queue": [{
        "size": 13
      },
      {
        "size": 10
      }]
    }