Skip to content

Commit 9180e29

Browse files
Merge pull request #29 from gravity9-tech/feature/7_json_path_readme
Feature/7 json path readme
2 parents c19e3d8 + 8036ade commit 9180e29

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,36 @@ Before:
432432
`{ "op": "test", "path": "/a", "value": "test-value" }`
433433

434434

435+
## JsonPath examples
436+
437+
JsonPath is supported in all operations (`add`, `remove`, `copy`, `replace`, `move`, `test`).
438+
439+
Examples of JsonPath:
440+
441+
* `$.store.bicycle.price` - Get price of bicycle in store
442+
* `$.store.book[*].pages` - Get pages from all books in store
443+
* `$..book[*].pages` - Get pages from all books which are a descent of root node
444+
* `$.store.book[-1:].pages` - Get pages from last book in store
445+
* `$.store.book[:2].pages` - Get pages of first two books in store
446+
* `$.store.book[?(@.author=='J.R.R. Tolkien')].pages` - Get pages of books written by J.R.R. Tolkien
447+
* `$..book[?(@.isbn)].pages` - Get pages of books which contain `isbn` property
448+
* `$..book[?(!@.isbn)].pages` - Get pages of books which do not contain `isbn` property
449+
* `$..book[?(@.price < 8.99)].pages` - Get pages of books which price is lower than `8.99`
450+
* `$..book[?(@.author =~ /.*Tolkien/i)].pages` - Pages of books whose author name ends with Tolkien (case-insensitive).
451+
* `$..book[?(@.category == 'fiction' || @.category == 'reference')]` - All books in `fiction` or `reference` category
452+
* `$..book[?(@.category in ['fiction', 'reference'])]` - All books in `fiction` or `reference` category
453+
* `$..book[?(@.category nin ['fiction'])]` - All books not in `fiction` category
454+
* `$..book[?(@.category=='fiction' && @.price < 10)].pages` - List of pages of books in `fiction` category and price lower than `10`
455+
* `$..book[?(@.tags subsetof ['tag1', 'tag2'])]` - All books with list of tags which is subset of `['tag1', 'tag2']`
456+
* `$..book[?(@.tags contains 'tag2')]` - All books with list of tags containing `tag2`
457+
* `$..book[?(@.tags size 2)]` - All books with list of tags containing exactly 2 elements
458+
* `$..book[?(@.tags empty true)]` - All books with empty list of tags
459+
* `$..book[?(@.tags empty false)]` - All books with not empty list of tags
460+
461+
### Limitations
462+
463+
* `$..book[(@.length-1)].title` - not supported. Use `$..book[-1:].title` instead.
464+
435465
[LGPLv3 badge]: https://img.shields.io/:license-LGPLv3-blue.svg
436466
[LGPLv3]: http://www.gnu.org/licenses/lgpl-3.0.html
437467
[ASL 2.0 badge]: https://img.shields.io/:license-Apache%202.0-blue.svg

0 commit comments

Comments
 (0)