Filter expression with equals on object with key matching query
Setup
Selector: $[?(@.id==2)]
{"id": 2}
Results
Consensus
[]
Not found consensus
This consensus applies for implementations which return a specific not found value if no match exists.
NOT_FOUND
Other responses
C (json-glib)
Not supported
Unable to compile selector `$[?(@.id==2)]': Invalid array index definition “?(@.id==2)]”
Clojure (json-path)
¹
[
2
]
Elixir (warpath)
¹
[
{
"id": 2
}
]
[
{
"id": 2
}
]
JavaScript (Goessner)
²
[
2
]
JavaScript (brunerd)
[
2
]
JavaScript (jsonpathly)
[
{
"id": 2
}
]
Java (com.jayway.jsonpath)
¹
³
[
{
"id": 2
}
]
Kotlin (com.nfeld.jsonpathkt)
¹
Not supported
Unexpected char, char=?, index=2
Objective-C (SMJJSONPath)
¹
³
[
{
"id": 2
}
]
PHP (remorhaz-jsonpath)
[
{
"id": 2
}
]
Python (jsonpath-ng)
Not supported
JsonPathLexerError('Error on line 1, col 2: Unexpected character: ? ')
Python (jsonpath-rw)
Not supported
JsonPathLexerError('Error on line 1, col 2: Unexpected character: ? ')
Python (jsonpath2)
Not supported
line 1:9 extraneous input '=' expecting {'@', '$', 'true', 'false', 'null', '{', '[', STRING, NUMBER}
ValueError("line 1:9 extraneous input '=' expecting {'@', '$', 'true', 'false', 'null', '{', '[', STRING, NUMBER}")
Raku (JSON-Path)
Not supported
Evaluation of embedded Perl 6 code not allowed (construct with :allow-eval)
Ruby (jsonpath)
[
{
"id": 2
}
]
Rust (jsonpath_lib)
[
{
"id": 2
}
]
Scala (jsonpath)
[
{
"id": 2
}
]
Swift (Sextant)
[
{
"id": 2
}
]
Errors
key error: not found in object
PHP (Goessner)
²
ArgumentCountError
Perl (JSON-Path)
non-safe evaluation, died at main.pl line 11.
Footnotes
- ¹ This implementation returns a single value where only one match is possible (instead of an array of a single value).
- ² This implementation returns a specific not found value if no match exists.
- ³ This implementation returns a specific not found value if a query that would regularly return a single match results in no match.