XPath JPath vs Internal Path - adsicks/gambas-json GitHub Wiki
JSONPath is described here. The gambas-json application will accept XPath, JSONPath, or ZPath formats. The format can be set with an Object Property and a flag.
Element | XPath | JSONPath | ZPath |
---|---|---|---|
root | / | $ | $ |
current | . | @ | . |
child | / | . or [] | / or /[] |
parent | .. | n/a | .. |
recursive descent | // | .. | /*/ |
subscript operator | [] | [] | [] |
union operator | | | [,] | &+ |
array slice operator | n/a | [start: end: step] | [<start>-<end>] |
script | [] | ?() | @<cmd> |
Sample XPath/JSONPath file.
XPath | JSONPath | ZPath | Result |
---|---|---|---|
/store/book/author | $.store.book[*].author | $/store/book[*]/author | the authors of all books in the store |
//author | $..author | $/*/author | all authors |
/store/* | $.store.* | $/store/*/ | all things in store, which are some books and a red bicycle. |
/store//price | $.store..price | $/store/*/price | the price of everything in the store. |
//book[3] | $..book[2] | $/*/book[2] | the third book |
//book[last()] | $..book[(@.length-1)] | $/*/book[(@count-1)] | |
$..book[-1:] | the last book in order. | ||
//book[position()<3] | $..book[0,1] | $/*/book[0-1] | |
$..book[:2] | the first two books | ||
//book[isbn] | $..book[?(@.isbn)] | $//book[]@where(./isbn!=null) | filter all books with isbn number |
//book[price<10] | $..book[?(@.price<10)] | $//book[]@where(./price<10) | filter all books cheaper than 10 |
//* | $..* | $/*/ | all Elements in XML document. All members of JSON structure. |
The Result is a collection with the ZPath as the key and the value as the value. Similar to combining res1 and res2 in the JSONPath example into a single associative array.