JsonPath 语法 与 XPath 对比
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
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
{ "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 语法 与 XPath 对比的更多相关文章
- [SoapUI] JsonPath 语法 与 XPath 对比
XPath JSONPath Description / $ the root object/element . @ the current object/element / . or [] chil ...
- jsonpath语法的基本使用
jsonpath的安装及使用方式: pip安装: Python3.7\Scripts> pip install jsonpath jsonpath的使用: obj = json.load(ope ...
- MySQL与Oracle的语法区别详细对比
MySQL与Oracle的语法区别详细对比 Oracle和mysql的一些简单命令对比在本文中将会涉及到很多的实例,感兴趣的你不妨学习一下,就当巩固自己的知识了 Oracle和mysql的一些简单 ...
- 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的'//'都表示 ...
- 关于XPath的基本语法
关于XPath基础语法 关于XPath基础语法 更详细的请看: XPath语法 XPath 使用路径表达式来选取 XML 文档中的节点或节点集.节点是通过沿着路径 (path) 或者步 (steps) ...
随机推荐
- unity5 manifest
https://www.cnblogs.com/lancidie/p/5878789.html 之前曾经写了一篇博客介绍Unity5的AssetBundle,结果似乎很受关注.不过似乎很多人看了之后都 ...
- 51nod 1562 玻璃切割
1562 玻璃切割 http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1562 题目来源: CodeForces 基准时间 ...
- IOS 版本控制判断
// 版本判断#define SYSTEM_VERSION(ver) [[[UIDevice currentDevice] systemVersion] compare:ver] != NSOrder ...
- [转] iOS开发-搜索栏UISearchBar和UISearchController
原文网址: http://www.cnblogs.com/xiaofeixiang/p/4273620.html?utm_source=tuicool iOS中UISearchDisplayContr ...
- Python小世界:彻底搞懂Python一切皆对象!!!
前言 犹记得当初学习Python的时候,对于Python一切皆对象很是懵逼,因为Python是面向对象的动态型语言,而在函数及高阶函数的应用中,如若对于一切皆对象不是有很透彻的了解,基础不是那么牢固的 ...
- SpringMVC入门 bug集锦X2
package cn.itcast.converter; import org.springframework.core.convert.converter.Converter; import jav ...
- 长春理工大学第十四届程序设计竞赛(重现赛)J.Printout
链接:https://ac.nowcoder.com/acm/contest/912/J 题意: 小r为了打校赛,他打算去打字社打印一份包含世界上所有算法的模板. 到了打字社,小r一看价格:总打印页数 ...
- CodeForces - 507B - Amr and Pins(计算几何)
Amr loves Geometry. One day he came up with a very interesting problem. Amr has a circle of radius r ...
- Control中的AOP实现非业务需求
一.能够使用Control中的AOP实现非业务需求的功能 本文目录 一.ActionFilterAttribute类 二.实现自定义Attribute 一.ActionFilterAttribute类 ...
- Java 2 个 List 集合数据求并、补集操作
开发过程中,我们可能需要对 2 个 或多个 List 集合中的数据进行处理,比如多个 List 集合数据求 相同元素,多个 List 集合数据得到只属于本身的数据,如图示: 这里写图片描述 这里以 2 ...