Filtering with ParseJSON

Just because nobody else will probably answer this because somehow JSONPath is overlooked in any learning materials…

If your JSON is like this:

{
    "events" : [
        {
            "name" : "Small event",
            "attendees" : [
                {"name": "Paul"},
                {"name": "Cathy"}
            ]
        },
        {
            "name" : "Large event",
            "attendees" : [
                {"name": "Paul"},
                {"name": "Alex"},
                {"name": "Joe"},
                {"name": "Nadia"},
                {"name": "Maria"},
                {"name": "Tracy"}
            ]
        }
    ]
}

then to filter down for events that have more than 5 attendees, use this JSONPath:

$.events[?(@.attendees.length > 5)]

For everyone’s reference:

  • $ is like thisTable (or thisJson actually)
  • [?( ... )] is like .Filter(...)
  • and @ is like CurrentValue :slight_smile:
5 Likes