Skip to content

Commit 6043dd4

Browse files
committed
- Enhancement: Add @root filter selector
- npm: Bump to 1.2.0
1 parent e38e3af commit 6043dd4

File tree

12 files changed

+32
-7
lines changed

12 files changed

+32
-7
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGES for jsonpath-plus
22

3+
## 1.2.0 (October 13, 2019)
4+
5+
- Enhancement: Add `@root` filter selector
6+
37
## 1.1.0 (September 26, 2019)
48

59
- Enhancement: Add explicit 'any' to `evaluate()` declaration (for use

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ did not spell out.
2121
* `@other()` usable in conjunction with a user-defined `otherTypeCallback`
2222
* Non-JSON types that can nevertheless be used when querying
2323
non-JSON JavaScript objects (`@undefined()`, `@function()`, `@nonFinite()`)
24-
* `@path`/`@parent`/`@property`/`@parentProperty` **shorthand selectors** within filters
24+
* `@path`/`@parent`/`@property`/`@parentProperty`/`@root` **shorthand selectors** within filters
2525
* **Escaping**
2626
* `` ` `` for escaping remaining sequence
2727
* `@['...']`/`?@['...']` syntax for escaping special characters within
@@ -310,6 +310,7 @@ comparisons or to prevent ambiguity).
310310
//book/*\[position() != 0] | $..book\[?(@property !== 0)] | Grabs all books whose property (which, being that we are reaching inside an array, is the numeric index) is not 0 | @property is not present in the original spec
311311
/store/\*/\*\[name(parent::*) != 'book'] | $.store.*\[?(@parentProperty !== "book")] | Grabs the grandchildren of store whose parent property is not book (i.e., bicycle's children, "color" and "price") | @parentProperty is not present in the original spec
312312
//book\[count(preceding-sibling::\*) != 0]/\*/text() | $..book.*\[?(@parentProperty !== 0)] | Get the property values of all book instances whereby the parent property of these values (i.e., the array index holding the book item parent object) is not 0 | @parentProperty is not present in the original spec
313+
//book\[price = /store/book\[3]/price] | $..book\[?(@.price === @root.store.book\[2].price)] | Filter all books whose price equals the price of the third book | @root is not present in the original spec
313314
//book/../\*\[. instance of element(\*, xs:decimal)\] (in XPath 2.0) | $..book..\*@number() | Get the numeric values within the book array | @number(), the other basic types (@boolean(), @string()), other low-level derived types (@null(), @object(), @array()), the JSONSchema-added type, @integer(), the compound type @scalar() (which also accepts `undefined` and non-finite numbers for JavaScript objects as well as all of the basic non-object/non-function types), the type, @other(), to be used in conjunction with a user-defined callback (see `otherTypeCallback`) and the following non-JSON types that can nevertheless be used with JSONPath when querying non-JSON JavaScript objects (@undefined(), @function(), @nonFinite()) are not present in the original spec
314315
| | `` ` `` (e.g., `` `$`` to match a property literally named `$`) | Escapes the entire sequence following (to be treated as a literal) | `` ` `` is not present in the original spec; to get a literal backtick, use an additional backtick to escape
315316

dist/index-es.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,11 @@ JSONPath.prototype._eval = function (code, _v, _vname, path, parent, parentPropN
817817
code = code.replace(/@path/g, '_$_path');
818818
}
819819

820+
if (code.includes('@root')) {
821+
this.currSandbox._$_root = this.json;
822+
code = code.replace(/@root/g, '_$_root');
823+
}
824+
820825
if (code.match(/@([\t-\r \)\.\[\xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF])/)) {
821826
this.currSandbox._$_v = _v;
822827
code = code.replace(/@([\t-\r \)\.\[\xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF])/g, '_$_v$1');

dist/index-es.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index-es.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index-umd.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,11 @@
823823
code = code.replace(/@path/g, '_$_path');
824824
}
825825

826+
if (code.includes('@root')) {
827+
this.currSandbox._$_root = this.json;
828+
code = code.replace(/@root/g, '_$_root');
829+
}
830+
826831
if (code.match(/@([\t-\r \)\.\[\xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF])/)) {
827832
this.currSandbox._$_v = _v;
828833
code = code.replace(/@([\t-\r \)\.\[\xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF])/g, '_$_v$1');

dist/index-umd.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index-umd.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"author": "Stefan Goessner",
33
"name": "jsonpath-plus",
4-
"version": "1.1.0",
4+
"version": "1.2.0",
55
"main": "dist/index-umd.js",
66
"module": "dist/index-es.js",
77
"types": "./src/jsonpath.d.ts",

0 commit comments

Comments
 (0)