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

Quoted subscript can not work will with union/or subscripts. #159

Open
nielinjie opened this issue Sep 28, 2021 · 2 comments
Open

Quoted subscript can not work will with union/or subscripts. #159

nielinjie opened this issue Sep 28, 2021 · 2 comments

Comments

@nielinjie
Copy link

Describe the bug

escape with quoted subscript can not work will with union/or subscripts.

Code sample or steps to reproduce

//PASS
test.only("some path with OR subscripts", () => {
  const obj = { functions: { foo: { io: "foo" }, bar: { out: "bar" } } };
  const jsonp = "$..[io,out]";
  const paths = jp.paths(obj, jsonp);
  expect(paths).toEqual([
    ["$", "functions", "foo", "io"],
    ["$", "functions", "bar", "out"],
  ]);
});
//PASS
test.only("some path with ESCAPE", () => {
  const obj = { functions: { foo: { "io.nest": "foo" }, bar: { out: "bar" } } };
  const jsonp = "$..['io.nest']";
  const paths = jp.paths(obj, jsonp);
  expect(paths).toEqual([
    ["$", "functions", "foo", "io.nest"],
  ]);
});
//FAILED
test.only("some path with ESCAPE and OR subscripts", () => {
  const obj = { functions: { foo: { 'io.nest': "foo" }, bar: { out: "bar" } } };
  const jsonp = "$..['io.nest',out]";
  const paths = jp.paths(obj, jsonp);
  expect(paths).toEqual([
    ["$", "functions", "foo", "io.nest"],
    ["$", "functions", "bar", "out"],
  ]);
});

Console error or logs

Expected behavior

All test case above should pass.

Expected result

Environment (IMPORTANT)

  • JSONPath-Plus version: 6.0.1

Desktop**

  • OS: Mac
  • Node Version: 15.12.0
@brettz9
Copy link
Collaborator

brettz9 commented Oct 21, 2021

The project is not really being actively maintained, but you'd have a better chance I think if your code sample worked for this library. The API you are using in your sample does not match this project.

@nielinjie
Copy link
Author

Sorry,I should mentioned that jp.paths in codes is just a help function for this:

import { JSONPath } from "jsonpath-plus";
const jp = {
  paths: (obj: any, path: string) => {
    return JSONPath({ path, json: obj, resultType: "path" }).map(
      JSONPath.toPathArray
    );
  },

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

2 participants