Search code examples
jsonjsonata

Jsonata filter value by looking at parent element


I've a JSON blob in the following form:

{
  "allEntries": [
     {
        "property": {
           "type": "ab"
        }, "values": {
           "score": 10.40
        }
     },
     {
        "property": {
           "type": "ty"
        }, "values": {
           "score": 90.45
        }
     }

  ]
}

I want to just check if the score of property type ab is less than 10. However $min(allEntries.values.score) goes through all the properties and does not filter out types which I'm not interested in. I tried using the parent property '%.' however that doesn't work either (The object representing the 'parent' cannot be derived from this expression)


Solution

  • You haven't said what the desired output is, but you can filter the list of array entries using the following expression:

    allEntries[property.type='ab' and values.score < 10]
    

    See https://try.jsonata.org/BzJKGrIIG