How to filter list by nested element using JSONPath?

4k views Asked by At

How can one filter a list of items by a deeply nested value using JSONPath?

Test Data

[{
    "identifiers": [
        {
            "extension": "foo"
        }
    ]
},
{
    "identifiers": [
        {
            "extension": "bar"
        },
        {
            "extension": "baz"
        }
    ]
}]

Expected Result

[{
    "identifiers": [
        {
            "extension": "foo"
        }
    ]
}]

I've tried the following, but none of them work. I used the JSONPath Tester to validate my results.

$[?(@.identifiers.[*].extension == 'foo')]
$[?(@.identifiers.*.extension == 'foo')]
$[?(@.identifiers[0].extension == 'foo')]
1

There are 1 answers

1
stefankmitph On

This

$..identifiers.[?(@.extension == "foo")]

works at http://jsonpath.herokuapp.com/ when you use Goessner.

at http://jsonpath.curiousconcept.com/ I keep getting errors.