简体   繁体   中英

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 )

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM