Filter expression with value

Setup

Selector: $[?(@.key)]

[
  {
    "some": "some value"
  },
  {
    "key": true
  },
  {
    "key": false
  },
  {
    "key": null
  },
  {
    "key": "value"
  },
  {
    "key": ""
  },
  {
    "key": 0
  },
  {
    "key": 1
  },
  {
    "key": -1
  },
  {
    "key": 42
  },
  {
    "key": {}
  },
  {
    "key": []
  }
]

Results

Other responses

Bash (JSONPath.sh)

[]

C (json-glib)

Not supported

Unable to compile selector `$[?(@.key)]': Invalid array index definition “?(@.key)]”

Clojure (json-path) ¹

[
  {
    "key": true
  },
  {
    "key": false
  },
  {
    "key": "value"
  },
  {
    "key": ""
  },
  {
    "key": 0
  },
  {
    "key": 1
  },
  {
    "key": -1
  },
  {
    "key": 42
  },
  {
    "key": {}
  },
  {
    "key": []
  }
]

Cpp (jsoncons)

[
  {
    "key": true
  },
  {
    "key": "value"
  },
  {
    "key": 0
  },
  {
    "key": 1
  },
  {
    "key": -1
  },
  {
    "key": 42
  }
]

Dart (json_path)

[
  {
    "key": true
  },
  {
    "key": false
  },
  {
    "key": null
  },
  {
    "key": "value"
  },
  {
    "key": ""
  },
  {
    "key": 0
  },
  {
    "key": 1
  },
  {
    "key": -1
  },
  {
    "key": 42
  },
  {
    "key": {}
  },
  {
    "key": []
  }
]

Elixir (ExJsonPath)

Not supported

syntax error before: ')'

Elixir (jaxon)

[]

Elixir (warpath) ¹

[
  {
    "key": true
  },
  {
    "key": false
  },
  {
    "key": null
  },
  {
    "key": "value"
  },
  {
    "key": ""
  },
  {
    "key": 0
  },
  {
    "key": 1
  },
  {
    "key": -1
  },
  {
    "key": 42
  },
  {
    "key": {}
  },
  {
    "key": []
  }
]

Erlang (ejsonpath)

[
  {
    "key": true
  },
  {
    "key": false
  },
  {
    "key": null
  },
  {
    "key": "value"
  },
  {
    "key": ""
  },
  {
    "key": 0
  },
  {
    "key": 1
  },
  {
    "key": -1
  },
  {
    "key": 42
  },
  {
    "key": {}
  },
  {
    "key": []
  }
]

Golang (github.com-PaesslerAG-jsonpath) ¹

[
  {
    "key": true
  },
  {
    "key": 1
  },
  {
    "key": -1
  },
  {
    "key": 42
  }
]

Golang (github.com-bhmj-jsonslice) ¹ ³

[
  {
    "key": true
  },
  {
    "key": "value"
  },
  {
    "key": 1
  },
  {
    "key": -1
  },
  {
    "key": 42
  },
  {
    "key": {}
  },
  {
    "key": []
  }
]

Golang (github.com-ohler55-ojg)

[
  {
    "key": true
  }
]

Golang (github.com-oliveagle-jsonpath) ¹

[]

Golang (github.com-spyzhov-ajson)

[
  {
    "key": true
  },
  {
    "key": "value"
  },
  {
    "key": 1
  },
  {
    "key": -1
  },
  {
    "key": 42
  }
]

Golang (github.com-vmware-labs-yaml-jsonpath)

[
  {
    "key": true
  },
  {
    "key": false
  },
  {
    "key": null
  },
  {
    "key": "value"
  },
  {
    "key": ""
  },
  {
    "key": 0
  },
  {
    "key": 1
  },
  {
    "key": -1
  },
  {
    "key": 42
  },
  {
    "key": {}
  },
  {
    "key": []
  }
]

Haskell (jsonpath)

[
  {
    "key": true
  },
  {
    "key": false
  },
  {
    "key": null
  },
  {
    "key": "value"
  },
  {
    "key": ""
  },
  {
    "key": 0
  },
  {
    "key": 1
  },
  {
    "key": -1
  },
  {
    "key": 42
  },
  {
    "key": {}
  },
  {
    "key": []
  }
]

JavaScript (Goessner) ²

[
  {
    "key": true
  },
  {
    "key": "value"
  },
  {
    "key": 1
  },
  {
    "key": -1
  },
  {
    "key": 42
  },
  {
    "key": {}
  },
  {
    "key": []
  }
]

JavaScript (brunerd)

[
  {
    "key": true
  },
  {
    "key": false
  },
  {
    "key": null
  },
  {
    "key": "value"
  },
  {
    "key": ""
  },
  {
    "key": 0
  },
  {
    "key": 1
  },
  {
    "key": -1
  },
  {
    "key": 42
  },
  {
    "key": {}
  },
  {
    "key": []
  }
]

JavaScript (jsonpath)

[
  {
    "key": true
  },
  {
    "key": "value"
  },
  {
    "key": 1
  },
  {
    "key": -1
  },
  {
    "key": 42
  },
  {
    "key": {}
  },
  {
    "key": []
  }
]

JavaScript (jsonpath-plus)

[
  {
    "key": true
  },
  {
    "key": "value"
  },
  {
    "key": 1
  },
  {
    "key": -1
  },
  {
    "key": 42
  },
  {
    "key": {}
  },
  {
    "key": []
  }
]

JavaScript (jsonpathly)

[
  {
    "key": true
  },
  {
    "key": false
  },
  {
    "key": null
  },
  {
    "key": "value"
  },
  {
    "key": ""
  },
  {
    "key": 0
  },
  {
    "key": 1
  },
  {
    "key": -1
  },
  {
    "key": 42
  },
  {
    "key": {}
  },
  {
    "key": []
  }
]

Java (com.github.jsurfer)

[
  {
    "key": true
  },
  {
    "key": false
  },
  {
    "key": null
  },
  {
    "key": "value"
  },
  {
    "key": ""
  },
  {
    "key": 0
  },
  {
    "key": 1
  },
  {
    "key": -1
  },
  {
    "key": 42
  },
  {
    "key": {}
  },
  {
    "key": []
  }
]

Java (com.jayway.jsonpath) ¹ ³

[
  {
    "key": true
  },
  {
    "key": false
  },
  {
    "key": null
  },
  {
    "key": "value"
  },
  {
    "key": ""
  },
  {
    "key": 0
  },
  {
    "key": 1
  },
  {
    "key": -1
  },
  {
    "key": 42
  },
  {
    "key": {}
  },
  {
    "key": []
  }
]

Kotlin (com.nfeld.jsonpathkt) ¹

Not supported

Unexpected char, char=?, index=2

Objective-C (SMJJSONPath) ¹ ³

[
  {
    "key": true
  },
  {
    "key": false
  },
  {
    "key": null
  },
  {
    "key": "value"
  },
  {
    "key": ""
  },
  {
    "key": 0
  },
  {
    "key": 1
  },
  {
    "key": -1
  },
  {
    "key": 42
  },
  {
    "key": {}
  },
  {
    "key": []
  }
]

PHP (galbar-jsonpath)

[
  {
    "key": true
  },
  {
    "key": null
  },
  {
    "key": "value"
  },
  {
    "key": ""
  },
  {
    "key": 0
  },
  {
    "key": 1
  },
  {
    "key": -1
  },
  {
    "key": 42
  },
  {
    "key": []
  },
  {
    "key": []
  }
]

PHP (remorhaz-jsonpath)

[
  {
    "key": true
  },
  {
    "key": false
  },
  {
    "key": null
  },
  {
    "key": "value"
  },
  {
    "key": ""
  },
  {
    "key": 0
  },
  {
    "key": 1
  },
  {
    "key": -1
  },
  {
    "key": 42
  },
  {
    "key": {}
  },
  {
    "key": []
  }
]

PHP (softcreatr-jsonpath)

[
  {
    "key": true
  },
  {
    "key": "value"
  },
  {
    "key": 1
  },
  {
    "key": -1
  },
  {
    "key": 42
  },
  {
    "key": {}
  }
]

Python (jsonpath) ²

[
  {
    "key": true
  },
  {
    "key": "value"
  },
  {
    "key": 1
  },
  {
    "key": -1
  },
  {
    "key": 42
  }
]

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)

[]

Python (python-jsonpath)

[
  {
    "key": true
  },
  {
    "key": false
  },
  {
    "key": null
  },
  {
    "key": "value"
  },
  {
    "key": ""
  },
  {
    "key": 0
  },
  {
    "key": 1
  },
  {
    "key": -1
  },
  {
    "key": 42
  },
  {
    "key": {}
  },
  {
    "key": []
  }
]

Raku (JSON-Path)

Not supported

Evaluation of embedded Perl 6 code not allowed (construct with :allow-eval)

Ruby (jsonpath)

[
  {
    "key": true
  },
  {
    "key": "value"
  },
  {
    "key": ""
  },
  {
    "key": 0
  },
  {
    "key": 1
  },
  {
    "key": -1
  },
  {
    "key": 42
  },
  {
    "key": {}
  },
  {
    "key": []
  }
]

Rust (jsonpath)

Not supported

parsing error

Rust (jsonpath_lib)

[
  {
    "key": true
  },
  {
    "key": false
  },
  {
    "key": null
  },
  {
    "key": "value"
  },
  {
    "key": ""
  },
  {
    "key": 0
  },
  {
    "key": 1
  },
  {
    "key": -1
  },
  {
    "key": 42
  },
  {
    "key": {}
  },
  {
    "key": []
  }
]

Rust (jsonpath_plus)

[
  {
    "key": true
  }
]

Rust (serde_json_path)

[
  {
    "key": true
  },
  {
    "key": false
  },
  {
    "key": null
  },
  {
    "key": "value"
  },
  {
    "key": ""
  },
  {
    "key": 0
  },
  {
    "key": 1
  },
  {
    "key": -1
  },
  {
    "key": 42
  },
  {
    "key": {}
  },
  {
    "key": []
  }
]

Scala (jsonpath)

[
  {
    "key": true
  },
  {
    "key": false
  },
  {
    "key": null
  },
  {
    "key": "value"
  },
  {
    "key": ""
  },
  {
    "key": 0
  },
  {
    "key": 1
  },
  {
    "key": -1
  },
  {
    "key": 42
  },
  {
    "key": {}
  },
  {
    "key": []
  }
]

Swift (Sextant)

[
  {
    "key": true
  },
  {
    "key": false
  },
  {
    "key": null
  },
  {
    "key": "value"
  },
  {
    "key": ""
  },
  {
    "key": 0
  },
  {
    "key": 1
  },
  {
    "key": -1
  },
  {
    "key": 42
  },
  {
    "key": {}
  },
  {
    "key": []
  }
]

dotNET (Json.NET)

[
  {
    "key": true
  },
  {
    "key": false
  },
  {
    "key": null
  },
  {
    "key": "value"
  },
  {
    "key": ""
  },
  {
    "key": 0
  },
  {
    "key": 1
  },
  {
    "key": -1
  },
  {
    "key": 42
  },
  {
    "key": {}
  },
  {
    "key": []
  }
]

dotNET (JsonCons.JsonPath)

[
  {
    "key": true
  },
  {
    "key": "value"
  },
  {
    "key": 0
  },
  {
    "key": 1
  },
  {
    "key": -1
  },
  {
    "key": 42
  }
]

dotNET (JsonPath.Net)

[
  {
    "key": true
  },
  {
    "key": false
  },
  {
    "key": null
  },
  {
    "key": "value"
  },
  {
    "key": ""
  },
  {
    "key": 0
  },
  {
    "key": 1
  },
  {
    "key": -1
  },
  {
    "key": 42
  },
  {
    "key": {}
  },
  {
    "key": []
  }
]

dotNET (Manatee.Json)

[
  {
    "key": true
  },
  {
    "key": null
  },
  {
    "key": "value"
  },
  {
    "key": ""
  },
  {
    "key": 0
  },
  {
    "key": 1
  },
  {
    "key": -1
  },
  {
    "key": 42
  },
  {
    "key": {}
  },
  {
    "key": []
  }
]

Errors

PHP (Goessner) ²

ArgumentCountError

Perl (JSON-Path)

non-safe evaluation, died at main.pl line 11.

dotNET (JsonPathLib)

Unable to cast object of type 'Newtonsoft.Json.Linq.JArray' to type 'System.IConvertible'.

Footnotes