JSONPath-Plus / JSONPath

A fork of JSONPath from http://goessner.net/articles/JsonPath/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

escaping in values raises errors

helloworld121 opened this issue · comments

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

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.

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)
commented

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