Open
Description
Describe the bug
As far as I can tell (sorry if I'm missing something), it appears to be impossible to select properties that contain a square bracket ([]
) in their name.
Code sample or steps to reproduce
Given the following JSON object:
{
"abc": 2,
"cd[DataLayer]": 1
}
I want to select the cd[DataLayer]
property. These are the expressions I have tried (unsuccessfully):
$["cd[DataLayer]"]
$['cd[DataLayer]']
$.cd[DataLayer]
$.cd`[DataLayer]
$.cd`[DataLayer`]
$['`cd[DataLayer]']
$['cd`[DataLayer]']
$['cd`[DataLayer]`']
$[?(@.property == 'cd[DataLayer]')]
$.cd\[DataLayer\]
$.cd.DataLayer
$[`cd[DataLayer]]
$[cd[DataLayer]]
Console error or logs
No errors for any of the expressions listed above, but they all return an empty result ([]
).
Expected behavior
I would expect there to be some expression that can select the cd[DataLayer]
property.
As per the json-path-comparison project, $[']']
should return [42]
for the input {"]": 42}
, which fails in jsonpath-plus: https://cburgmer.github.io/json-path-comparison/results/bracket_notation_with_quoted_closing_bracket_literal.html#JavaScript_jsonpath-plus
Expected result
[
1
]
Environment (IMPORTANT)
- Locally using JSONPath-Plus version: 7.2.0
- And on the demo page
Desktop
- Firefox 132.0b5 on Ubuntu 24.04.1 LTS
- Node v20.7.0