Filter or conditional statement on a simple document?

Viewed 157

On the below simple JSON document

{ "result" : 5 }

I would like to filter or apply a condition in order to get value matching result > 5

1 Answers

JMESPath is not really meant to act on a single object.

In order to achieve this, though, you can convert the object to an array, with the function to_array and back to an object, using | [0], in order to extract back the first element of the list, as explained in working with nested data.

All together, this gives the query:

to_array(@)[?result>`5`] | [0]
  • Which, on the JSON:
    { "result" : 5 }
    
    gives:
    null
    
  • And, on the JSON:
    { "result" : 6 }
    
    gives:
    {
      "result": 6
    }
    
Related