JamesNK / Newtonsoft.Json

Json.NET is a popular high-performance JSON framework for .NET
https://www.newtonsoft.com/json
MIT License
10.71k stars 3.24k forks source link

Filter where Array contains value using JSONPATH #2908

Closed aymanabollo closed 10 months ago

aymanabollo commented 10 months ago

Hi, I've a json string like the below, I need to check if array contains a specific value and I use this expression for this:

json.SelectTokens("$.name[?('Ahmad' in @.given )]")

but it seems like in keyword is not supported, I tried contains but also not working

json.SelectTokens("$.name[?(@.given.contains('Ahmad') )]")

I need to do the filtering in the JSONPATH string not using LINQ, is this a bug or am I missing something?

"name": [
    {
        "use": "official",
        "family": "Sayegh",
        "given": [
            "Ahmad"
        ],
        "prefix": [
            "Mr."
        ]
    },
    {
        "use": "usual",
        "family": "الصايغ",
        "given": [
"أحمد"
        ]
    }
]

Thanks