forked from java-json-tools/json-patch
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from gravity9-tech/feature/7_json_path_readme
Feature/7 json path readme
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -432,6 +432,36 @@ Before: | |
`{ "op": "test", "path": "/a", "value": "test-value" }` | ||
|
||
|
||
## JsonPath examples | ||
|
||
JsonPath is supported in all operations (`add`, `remove`, `copy`, `replace`, `move`, `test`). | ||
|
||
Examples of JsonPath: | ||
|
||
* `$.store.bicycle.price` - Get price of bicycle in store | ||
* `$.store.book[*].pages` - Get pages from all books in store | ||
* `$..book[*].pages` - Get pages from all books which are a descent of root node | ||
* `$.store.book[-1:].pages` - Get pages from last book in store | ||
* `$.store.book[:2].pages` - Get pages of first two books in store | ||
* `$.store.book[?(@.author=='J.R.R. Tolkien')].pages` - Get pages of books written by J.R.R. Tolkien | ||
* `$..book[?(@.isbn)].pages` - Get pages of books which contain `isbn` property | ||
* `$..book[?([email protected])].pages` - Get pages of books which do not contain `isbn` property | ||
* `$..book[?(@.price < 8.99)].pages` - Get pages of books which price is lower than `8.99` | ||
* `$..book[?(@.author =~ /.*Tolkien/i)].pages` - Pages of books whose author name ends with Tolkien (case-insensitive). | ||
* `$..book[?(@.category == 'fiction' || @.category == 'reference')]` - All books in `fiction` or `reference` category | ||
* `$..book[?(@.category in ['fiction', 'reference'])]` - All books in `fiction` or `reference` category | ||
* `$..book[?(@.category nin ['fiction'])]` - All books not in `fiction` category | ||
* `$..book[?(@.category=='fiction' && @.price < 10)].pages` - List of pages of books in `fiction` category and price lower than `10` | ||
* `$..book[?(@.tags subsetof ['tag1', 'tag2'])]` - All books with list of tags which is subset of `['tag1', 'tag2']` | ||
* `$..book[?(@.tags contains 'tag2')]` - All books with list of tags containing `tag2` | ||
* `$..book[?(@.tags size 2)]` - All books with list of tags containing exactly 2 elements | ||
* `$..book[?(@.tags empty true)]` - All books with empty list of tags | ||
* `$..book[?(@.tags empty false)]` - All books with not empty list of tags | ||
|
||
### Limitations | ||
|
||
* `$..book[(@.length-1)].title` - not supported. Use `$..book[-1:].title` instead. | ||
|
||
[LGPLv3 badge]: https://img.shields.io/:license-LGPLv3-blue.svg | ||
[LGPLv3]: http://www.gnu.org/licenses/lgpl-3.0.html | ||
[ASL 2.0 badge]: https://img.shields.io/:license-Apache%202.0-blue.svg | ||
|