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

escaping in values raises errors #160

Open
helloworld121 opened this issue Oct 7, 2021 · 3 comments
Open

escaping in values raises errors #160

helloworld121 opened this issue Oct 7, 2021 · 3 comments

Comments

@helloworld121
Copy link

helloworld121 commented Oct 7, 2021

Hi Brett,

I started using your project, and I love it.
But I got one issue with filtering for values, that contain brackets. I tried escaping those brackets but it doesn't work.
Could you take a look at this?

$.book[?(@.chapter === 'chap (1)')]
// Error: jsonPath: Invalid or unexpected token: _$_v.chapter === 'chap (1

I also tried to escape the value by using backticks. But it didn't work.
It is possible, that this is a bug?

It would be great if you could help me out.

Thank you very much,
Sebastian

@brettz9
Copy link
Collaborator

brettz9 commented Oct 9, 2021

Please provide a minimal reproducible test case--a small sample JSON file and the exact code you use to execute against it.

No guarantees anyone can work on it, as this library is not being actively maintained, but should be more likely someone can look into it.

You might also look at our test files to see how escaping is done there.

@helloworld121
Copy link
Author

Hi Brett,

thank you for your quick reply :)
Here is a small testcase that I can use to reproduce the error.
I already took a look at your testcases, but I didn't manage to make my case work.

Thank you very much,
Sebastian

import { JSONPath } from 'jsonpath-plus';

const exampleObject = {
  book: [
    {
      category: 'reference',
      chapter: 'chap (1)',
      author: 'Nigel Rees',
      title: 'Sayings of the Century',
      price: 8.95
    }
  ]
};

describe('tests for jsonpath-plus', function () {
  it('filter by attribute', function () {
    const test = JSONPath({
      path: "$.book[?(@.chapter === 'chap (1)')]",
      json: exampleObject
    });
  });
});

This results in:

	Error: jsonPath: Invalid or unexpected token: _$_v.chapter === 'chap (1
	    at JSONPath._eval (node_modules/jsonpath-plus/dist/index-browser-esm.js:902:1)
	    at node_modules/jsonpath-plus/dist/index-browser-esm.js:665:1
	    at JSONPath._walk (node_modules/jsonpath-plus/dist/index-browser-esm.js:827:1)

@ysrn
Copy link

ysrn commented Nov 2, 2021

$.book[?(@.chapter === 'chap (1)')] does fail, but $.book[?(@.chapter === "chap (1)")] (double-quotes) works.

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

3 participants