Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selecting properties containing a square bracket seems to be impossible #225

Open
baltpeter opened this issue Oct 14, 2024 · 0 comments
Open

Comments

@baltpeter
Copy link

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant