[SoapUI] JsonPath 语法 与 XPath 对比
| 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 have 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 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",
"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 are 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 in order. |
//book[position()<3] |
$..book[0,1]$..book[:2] |
the first two 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 JSON structure. |
需要的JAR包
json-path-0.9.1.jar
json-smart-1.2.jar
commons-lang-2.6.jar
一个更加全面的JsonPath讲解
https://github.com/json-path/JsonPath
| JsonPath (click link to try) | Result |
|---|---|
| $.store.book[*].author | The authors of all books |
| $..author | All authors |
| $.store.* | All things, both books and bicycles |
| $.store..price | The price of everything |
| $..book[2] | The third book |
| $..book[-2] | The second to last book |
| $..book[0,1] | The first two books |
| $..book[:2] | All books from index 0 (inclusive) until index 2 (exclusive) |
| $..book[1:2] | All books from index 1 (inclusive) until index 2 (exclusive) |
| $..book[-2:] | Last two books |
| $..book[2:] | Book number two from tail |
| $..book[?(@.isbn)] | All books with an ISBN number |
| $.store.book[?(@.price < 10)] | All books in store cheaper than 10 |
| $..book[?(@.price <= $['expensive'])] | All books in store that are not "expensive" |
| $..book[?(@.author =~ /.*REES/i)] | All books matching regex (ignore case) |
| $..* | Give me every thing |
| $..book.length() | The number of books |
[SoapUI] JsonPath 语法 与 XPath 对比的更多相关文章
- JsonPath 语法 与 XPath 对比
JsonPath 语法 与 XPath 对比 XPath JSONPath Description / $ the root object/element . @ the current obje ...
- jsonpath语法的基本使用
jsonpath的安装及使用方式: pip安装: Python3.7\Scripts> pip install jsonpath jsonpath的使用: obj = json.load(ope ...
- MySQL与Oracle的语法区别详细对比
MySQL与Oracle的语法区别详细对比 Oracle和mysql的一些简单命令对比在本文中将会涉及到很多的实例,感兴趣的你不妨学习一下,就当巩固自己的知识了 Oracle和mysql的一些简单 ...
- [SoapUI] JsonPath is to JSON what XPath is to XML
1.通过JsonUtil验证Json的有效性 2.两种方式通过JPath读取Json的内容
- MySQL与Oracle的语法区别详细对比 (转)
Oracle和mysql的一些简单命令对比 1) SQL> select to_char(sysdate,'yyyy-mm-dd') from dual; SQL> select to_c ...
- [转]MySQL与Oracle的语法区别详细对比
Oracle和mysql的一些简单命令对比 1) SQL> select to_char(sysdate,'yyyy-mm-dd') from dual; SQL> select to_c ...
- Golang 基础语法介绍及对比(二)
传值与传参 Golong func main() { a := fmt.Println("a = ", a) // 应该输出 "a= 3" a1 := add1 ...
- Python爬虫爬取异步加载的数据
前言 本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理.作者:努力努力再努力 爬取qq音乐歌手数据接口数据 https://y.qq ...
- 爬虫常用Xpath和CSS3选择器对比
爬虫常用Xpath和CSS3选择器对比 1. 简介 CSS是来配合HTML工作的,和Xpath对比起来,CSS选择器通常都比较短小,但是功能不够强大.CSS中的空白符' '和Xpath的'//'都表示 ...
随机推荐
- PHP使用RabbitMQ
基本概念 Broker:简单来说就是消息队列服务器实体. Exchange:消息交换机,它指定消息按什么规则,路由到哪个队列. Queue:消息队列载体,每个消息都会被投入到一个或多个队列. Bind ...
- Java--mysql实现分页查询--分页显示
当数据库中数据条数过多时,一个页面就不能显示,这是要设置分页查询,首先要使用的是数据库sql语句的limit条件实现分组查询sql语句大概形式为: select * from table limit ...
- MySQL 5.7 坑爹参数 – log_timestamps
官网原话: This variable was added in MySQL 5.7.2. Before 5.7.2, timestamps in log messages were written ...
- MySQL升级指南
一 .MySQL升级 1.官方升级策略 注意 升级过程中必须使用具有管理权限的MySQL帐户来执行SQL语句. 1.升级方法 逻辑升级: 涉及使用 mysqldump从旧的MySQL版本导出现有数据 ...
- Asp.net 的cookie问题
写代码的发现的小问题 如果写入cookie的时候指定了domin域名 那么删除的时候必须也指定domin域名才行,即使你先读取了这个已经存在的cookie,但是还是要指定domin才能删除 /// & ...
- [Python] IMG to Char
Change image into character from PIL import Image import argparse #输入 #命令行输入参数处理 parser = argparse.A ...
- django-bower
https://django-bower.readthedocs.io/en/latest/usage.html
- 使用CCNode作为容器容易踩的坑
Cocos2dx中CCNode经常作为一个父容器,里面装一些UI控件,最后组成一个复杂的自定义的UI控件,但是在使用别人的自定义控件和自己写自定义问题的时候会踩一些坑. 首先拿到一个自定义的UI控件一 ...
- Tkinter Text(文本)
Tkinter Text(文本): 文本小部件提供先进的功能,让您编辑多行文本格式,如改变其颜色和字体的方式显示. 文本小部件提供先进的功能,让您编辑多行文本格式,如改变其颜色和字体的方 ...
- numpy的通用函数
通用函数:快速的元素级数组函数 通用函数是一种对ndarry中的数据执行元素级运算的函数,可以看作是简单函数(接受一个或多个标量值,并产生一个或多个标量值)的矢量化包装器. 一元func: abs丶f ...