dchester / jsonpath

Query and manipulate JavaScript objects with JSONPath expressions. Robust JSONPath engine for Node.js.
MIT License
1.33k stars 215 forks source link

output of stringify function not compatible with query function #161

Open joelleortiz opened 3 years ago

joelleortiz commented 3 years ago

When using stringify, the path expression output is not directly compatible for use in the query function to get data from objects.

stringify output: $.response.items["*"]["iso-1234"]
query input: $.response.items[*]['iso-1234']

stringify output: $.items["*"]["\"te\\st\""]
query input: $.items[*]['\"te\\st\"']

i suspect it's because of the JSON.stringify step for string literals:

https://github.com/dchester/jsonpath/blob/c1dd8ec74034fb0375233abb5fdbec51ac317b4b/lib/index.js#L179

Are the two functions (stringify and query) meant to be used together in this way? Or is there any other way to generate a path expression from an array of element paths that can be directly used to query data later?

beckyconning commented 2 years ago

Struggling with the same issue of [*] becoming ["*"].