[SoapUI] JsonPath syntax vs. XPath

Source: Internet
Author: User
Tags xpath soapui

Xpath JSONPath Description
/ $ The root object/element
. @ The current object/element
/ . or [] Child operator
.. N/A Parent operator
// .. Recursive descent. JSONPath borrows this syntax from E4X.
* * Wildcard. All objects/elements regardless their names.
@ N/A Attribute access. JSON structures don ' t has attributes.
[] [] Subscript operator. XPath uses it to iterate over element collections and for predicates. In Javascript and JSON it is the native array operator.
| [,] Union operator in XPath results in a combination of node sets. JSONPath allows alternate names or array indices as a set.
N/A [Start:end:step] Array slice operator borrowed from ES4.
[] ? () Applies a filter (script) expression.
N/A () Script expression, using the underlying script engine.
() N/A Grouping in Xpath

JSONPath expressions can use the dot–notation

$.store.book[0].title

or the bracket–notation

$[‘store‘][‘book‘][0][‘title‘]

The following XPath expression

/store/book[1]/title

JsonPath would look like

x.store.book[0].title

Or

x[‘store‘][‘book‘][0][‘title‘]

JSONPath Examples
{"Store": {"book    ": [       {"category": "Reference",        "author": "Nigel Rees",        "title": "Sayings of the Centur Y ",        " 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",      "Price": 19.95    }}  }

  

Xpath JSONPath Result
/store/book/author $.store.book[*].author The authors of all books in the store
//author $..author All authors
/store/* $.store.* All things in store, which is some books and a red bicycle.
/store//price $.store..price The price of everything in the store.
//book[3] $..book[2] The third book
//book[last()] $..book[(@.length-1)]
$..book[-1:]
The last book is in order.
//book[position()<3] $..book[0,1]
$..book[:2]
The first and the books
//book[isbn] $..book[?(@.isbn)] Filter All books with ISBN number
//book[price<10] $..book[?(@.price<10)] Filter all books Cheapier than 10
//* $..* All Elements in XML document. All members of the JSON structure.

Required JAR Package

Json-path-0.9.1.jar

Json-smart-1.2.jar

Commons-lang-2.6.jar

[SoapUI] JsonPath syntax vs. XPath

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.