Skip to content

Commit 743fd1f

Browse files
committed
- Docs: Add example of regex on property
1 parent 1314832 commit 743fd1f

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ comparisons or to prevent ambiguity).
330330
//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
331331
//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
332332
//book/*[name() = 'category' and matches(., 'tion$')] (XPath 2.0) | $..book.*\[?(@property === "category" && @.match(/TION$/i))] | All categories of books which match the regex (end in 'TION' case insensitive) | @property is not present in the original spec.
333+
//book/*[matches(name(), 'bn$')]/parent::* (XPath 2.0) | $..book.*\[?(@property.match(/bn$/i))]^ | All books which have a property matching the regex (end in 'TION' case insensitive) | @property is not present in the original spec. Note: Uses the parent selector \^ at the end of the expression to return to the parent object; without the parent selector, it matches the two `isbn` key values.
333334
| | `` ` `` (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
334335

335336
Any additional variables supplied as properties on the optional "sandbox"

badges/tests-badge.svg

Lines changed: 1 addition & 1 deletion
Loading

test/test.examples.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,5 +253,15 @@ checkBuiltInVMAndNodeVM(function (vmType, setBuiltInState) {
253253
});
254254
assert.deepEqual(result, expected);
255255
});
256+
257+
it('Regex on property', () => {
258+
const books = json.store.book;
259+
const expected = [books[2], books[3]];
260+
const result = jsonpath({
261+
json,
262+
path: '$..book.*[?(@property.match(/bn$/i))]^'
263+
});
264+
assert.deepEqual(result, expected);
265+
});
256266
});
257267
});

0 commit comments

Comments
 (0)