[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的'//'都表示 ...
随机推荐
- CFile用法(转)
一.各种关于文件的操作在程序设计中是十分常见,如果能对其各种操作都了如指掌,就可以根据实际情况找到最佳的解决方案,从而在较短的时间内编写出高效的代码,因而熟练的掌握文件操作是十分重要的.本文将对Vis ...
- 1DAY 初识Python
一 本节目标 了解编程语言 了解python及与其他语言的优劣对比 安装python解释器及环境变量配置.运行python交互式环境 打印hello world程序 初识变量.用户输入,流程控制,wh ...
- 在centOS5.9安装asterisk
最近一直在研究asterisk这个服务器,Asterisk 是一个开放源代码的软件VoIP PBX系统,它是一个运行在Linux环境下的纯软件实施方案.Asterisk是一种功能非常齐全的应用程序,提 ...
- Php处理时间的函数
1,字符串与时间: 例如 $time = strtotime("2007-3-5"); echo date("Y-m-d H:i:s",$time); 2,当前 ...
- 关闭easyui Tabs,有意思的JS异步处理
因业务需要,需要将关闭windows窗口内的所有Tabs关闭掉,因此写了个方法,执行结果把我惊了一下. function closeAllTabs() { var tabsCount = $(&quo ...
- 使用Eclipse可以启动服务器,却不能访问localhost
今天心血来潮修改了Tomcat的端口号,将默认的8080改为8888,使用MyEclipse部署项目没有问题,只是访问的地址不可以使用8080而是要用8888,这是当然的了,毕竟我修改了.但是使用Ec ...
- mysqldumpl备份
mysqldump --databases mydatabase --lock-all-tables --flush-logs mysqldump -h10. -uroot -p密码 --databa ...
- python学习笔记(十):操作excel
一.python操作excel,python操作excel使用xlrd.xlwt和xlutils模块,xlrd模块是读取excel的,xlwt模块是写excel的,xlutils是用来修改excel的 ...
- Storm概念理解
组成: Topology是Storm里的最高抽象概念,相当于Hadoop里的MapReduce,Topology(流转换图)由Spouts和Bolts组成.Spout创建Stream,Stream由无 ...
- PHP程序连接多个redis实例做缓存
1.redis配置: $CONFIG_REDIS = array( array('host' => '192.168.19.29', 'port' => '6379', 'dbIn ...