grammar

JsonPath grammar A brief description
$ The root node
@ The current node
.or[] Child nodes
. Select all nodes that match the criteria
* All the nodes
[] An iterator identifier, such as a number of subscripts
[and] Support multiple selection in iterators
[start:end] Array slicing operator
? (a) Support filtering operations
(a) Support for expression evaluation

example

The json data

{ "store": { "book": [ { "category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95}, {"category": "fiction", "author": "Evelyn Waugh", "title": "Sword of Honour", "price": 12.99}, {"category": "Fiction ", "author": "Herman Melville", "title": "Moby Dick"," ISBN ": "0-553-21311-3", "price": 8.99}, {"category": "fiction", "author": "J. R. R. Tolkien", "title": "The Lord of the Rings", "isbn": "0-395-19395-8", "price": 22.99}], "bicycle" : {" color ":" red ", "author" : "DC - bicycle", "price" : 19.95}}, "expensive" : 10, "author":" dC-store ", "price": 33.33}Copy the code

Using json data as an example, the JsonPath syntax uses:

JsonPath expression describe
$.store.book[*].author store.bookAll under the nodeauthorvalue
$.. author All of theauthor
$.store.* storeAll values under the node, includingbook,bicycle
$.store.. price storeAll under the nodepricevalue
$.. book[2] The thirdbook
$.. book[-2] Penultimatebook
$.. The book [0, 1] The first, the secondbook
$.. book[:2] Subscript 0 to 2book
$.. book[1:2] Subscript 1 to 2book
$.. book[-2:] The last twobook
$.. book[2:] The subscript 2bookIn the end
$.. book[?(@.isbn)] All containisbnthebook
$.store.book[?(@.price < 10)] instoreUnder the node,priceLess than tenbook
$.. book[?(@.price <= $['expensive'])] instoreNode, not “Expensive”book
$.. book[?(@.author =~ /.*REES/i)] Matching regular expressions/.*REES/ithebook
$.. * Each node is output once
$.. book.length() bookThe number of

PS: The above JsonPath can be verified here