Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion badges/tests-badge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion dist/index-browser-esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -2168,7 +2168,7 @@ class JSONPathClass {
} else {
const valObj3 = /** @type {Record<string, unknown>} */val;
this._walk(val, m => {
if (this._eval(safeLoc, valObj3[m], m, path, parent, parentPropName)) {
if (this._eval(safeLoc, valObj3[m], m, path, Array.isArray(val) ? parent : val, parentPropName)) {
addRet(this._trace(x, valObj3[m], push(path, m), val, m, callback, true));
}
});
Expand Down
2 changes: 1 addition & 1 deletion dist/index-browser-esm.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index-browser-esm.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index-browser-umd.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2174,7 +2174,7 @@
} else {
const valObj3 = /** @type {Record<string, unknown>} */val;
this._walk(val, m => {
if (this._eval(safeLoc, valObj3[m], m, path, parent, parentPropName)) {
if (this._eval(safeLoc, valObj3[m], m, path, Array.isArray(val) ? parent : val, parentPropName)) {
addRet(this._trace(x, valObj3[m], push(path, m), val, m, callback, true));
}
});
Expand Down
2 changes: 1 addition & 1 deletion dist/index-browser-umd.min.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index-browser-umd.min.cjs.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index-node-cjs.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2172,7 +2172,7 @@ class JSONPathClass {
} else {
const valObj3 = /** @type {Record<string, unknown>} */val;
this._walk(val, m => {
if (this._eval(safeLoc, valObj3[m], m, path, parent, parentPropName)) {
if (this._eval(safeLoc, valObj3[m], m, path, Array.isArray(val) ? parent : val, parentPropName)) {
addRet(this._trace(x, valObj3[m], push(path, m), val, m, callback, true));
}
});
Expand Down
2 changes: 1 addition & 1 deletion dist/index-node-esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -2170,7 +2170,7 @@ class JSONPathClass {
} else {
const valObj3 = /** @type {Record<string, unknown>} */val;
this._walk(val, m => {
if (this._eval(safeLoc, valObj3[m], m, path, parent, parentPropName)) {
if (this._eval(safeLoc, valObj3[m], m, path, Array.isArray(val) ? parent : val, parentPropName)) {
addRet(this._trace(x, valObj3[m], push(path, m), val, m, callback, true));
}
});
Expand Down
4 changes: 2 additions & 2 deletions src/jsonpath.js
Original file line number Diff line number Diff line change
Expand Up @@ -756,8 +756,8 @@ class JSONPathClass {
} else {
const valObj3 = /** @type {Record<string, unknown>} */ (val);
this._walk(val, (m) => {
if (this._eval(safeLoc, valObj3[m], m, path, parent,
parentPropName)) {
if (this._eval(safeLoc, valObj3[m], m, path,
Array.isArray(val) ? parent : val, parentPropName)) {
addRet(this._trace(x, valObj3[m], push(path, m), val, m,
callback, true));
}
Expand Down
11 changes: 11 additions & 0 deletions test/test.examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,17 @@ checkBuiltInVMAndNodeVM(function (vmType, setBuiltInState) {
const result = jsonpath({json, path: '$..book[?(@parent.bicycle && @parent.bicycle.color === "red")].category'});
assert.deepEqual(result, expected);
});
it('uses the containing object as @parent in object filters', () => {
const data = {id: 1, foo: {id: 2, bar: {id: 3, foo: {id: 4}}}};
assert.deepEqual(jsonpath({
json: data,
path: '$.foo.bar[?(@property === "foo" && @parent.id === 3)]'
}), [data.foo.bar.foo]);
assert.deepEqual(jsonpath({
json: data,
path: '$.foo.bar[?(@property === "foo" && @parent.id === 2)]'
}), []);
});
it('Custom property: @property', () => {
const expected = json.store.book.reduce(function (arr, book) {
arr.push(book.author, book.title);
Expand Down