I have the following object and lodash "queries" in Node.js (I'm simply running node in the terminal):
var obj = { a: [{ b: [{ c: "apple" }, { d: "not apple" }, { c: "pineapple" }] }] }; > _.get(obj, "a[0].b[0].c") 'apple' > _.get(obj, "a[0].b[1].c") undefined > _.get(obj, "a[0].b[2].c") 'pineapple' My question is: is there a way to return an array of values where the path was found to be valid?
Example:
> _.get(obj, "a[].b[].c") ['apple', 'pineapple']
a[0].b? Or any path, as you provided in the question?jsonpath.query(obj, '$.a[*].b[*].c');