Skip to content

Commit caa25cd

Browse files
committed
Add minimal in-code documentation for JSONPath
1 parent b18daa5 commit caa25cd

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

src/js/jsonpath.js

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,60 @@
2020
2121
*/
2222

23-
/******************************************************************************/
23+
/**
24+
* Implement the parsing of uBO-flavored JSON path syntax
25+
*
26+
* Reference to original JSON path syntax:
27+
* https://goessner.net/articles/JsonPath/index.html
28+
*
29+
* uBO-flavored JSON path implementation differs as follow:
30+
*
31+
* - Both $ and @ are implicit. Though you can use them, you do not have to.
32+
* Use $ only when the implicit context is not that of root. Example:
33+
* - Official: $..book[?(@.isbn)]
34+
* - uBO-flavored: ..book[?(.isbn)]
35+
*
36+
* - uBO-flavor syntax do not (yet) support:
37+
* - Union (,) operator.
38+
* - Array slice operator
39+
*
40+
* - Regarding filter expressions, uBO-flavored JSON path supports a limited
41+
* set of expressions since unlike the official implementation, uBO can't use
42+
* JS eval() to evaluate arbitrary JS expressions. The operand MUST be valid
43+
* JSON. The currently supported expressions are:
44+
* - ==: strict equality
45+
* - !=: strict inequality
46+
* - <: less than
47+
* - <=: less than or equal to
48+
* - >: greater than
49+
* - >=: greater than or equal to
50+
* - ^=: stringified value starts with
51+
* - $=: stringified value ends with
52+
* - *=: stringified value includes
53+
*
54+
* - Examples (from "JSONPath examples" at reference link)
55+
* - .store.book[*].author
56+
* - ..author
57+
* - .store.*
58+
* - .store..price
59+
* - ..book[2]
60+
* - ..book[?(.isbn)]
61+
* - ..book[?(.price<10)]
62+
* - ..*
63+
*
64+
* uBO-flavored syntax supports assigning a value to a resolved JSON path by
65+
* appending `=[value]` to the JSON path. The assigned value MUST be valid JSON.
66+
* Examples:
67+
* - .store..price=0
68+
* - .store.book[*].author="redacted"
69+
*
70+
* A JSONPath instance can be use to compile a JSON path query, and the result
71+
* of the compilation can be applied to different objects. When a JSON path
72+
* query does not assign a value, the resolved property will be removed.
73+
*
74+
* More capabilities can be added in the future as needed.
75+
*
76+
* */
2477

2578
export class JSONPath {
2679
static create(query) {

0 commit comments

Comments
 (0)