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 对比的更多相关文章

  1. [SoapUI] JsonPath 语法 与 XPath 对比

    XPath JSONPath Description / $ the root object/element . @ the current object/element / . or [] chil ...

  2. jsonpath语法的基本使用

    jsonpath的安装及使用方式: pip安装: Python3.7\Scripts> pip install jsonpath jsonpath的使用: obj = json.load(ope ...

  3. MySQL与Oracle的语法区别详细对比

    MySQL与Oracle的语法区别详细对比 Oracle和mysql的一些简单命令对比在本文中将会涉及到很多的实例,感兴趣的你不妨学习一下,就当巩固自己的知识了   Oracle和mysql的一些简单 ...

  4. MySQL与Oracle的语法区别详细对比 (转)

    Oracle和mysql的一些简单命令对比 1) SQL> select to_char(sysdate,'yyyy-mm-dd') from dual; SQL> select to_c ...

  5. [转]MySQL与Oracle的语法区别详细对比

    Oracle和mysql的一些简单命令对比 1) SQL> select to_char(sysdate,'yyyy-mm-dd') from dual; SQL> select to_c ...

  6. Golang 基础语法介绍及对比(二)

    传值与传参 Golong func main() { a := fmt.Println("a = ", a) // 应该输出 "a= 3" a1 := add1 ...

  7. Python爬虫爬取异步加载的数据

    前言 本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理.作者:努力努力再努力 爬取qq音乐歌手数据接口数据 https://y.qq ...

  8. 爬虫常用Xpath和CSS3选择器对比

    爬虫常用Xpath和CSS3选择器对比 1. 简介 CSS是来配合HTML工作的,和Xpath对比起来,CSS选择器通常都比较短小,但是功能不够强大.CSS中的空白符' '和Xpath的'//'都表示 ...

  9. 关于XPath的基本语法

    关于XPath基础语法 关于XPath基础语法 更详细的请看: XPath语法 XPath 使用路径表达式来选取 XML 文档中的节点或节点集.节点是通过沿着路径 (path) 或者步 (steps) ...

随机推荐

  1. 符号分割的字符串转换为XML

    把某一符串分割的字符串转换为 XML格式: DECLARE @str NVARCHAR(MAX) = N'fd,re,45,tyu,976,qwer,gdsg,uyt' DECLARE @xml XM ...

  2. python读写xlsx

    1使用openpyxl库读写excel xlrd和xlwt处理的是xls文件,单个sheet最大行数是65535,如果有更大需要的,建议使用openpyxl函数,最大行数达到1048576.  如果数 ...

  3. Segment Tree Range Minimum Query.

    int rangeMinQuery(int segTree[], int qlow, int qhigh, int low, int high, int pos) { if (qlow <= l ...

  4. Solr 6.7学习笔记(02)-- 配置文件 managed-schema (schema.xml) - filter(5)

    自定义fieldType时,通常还会用到filter.filter必须跟在tokenizer或其它filter之后.如: <fieldType> <analyzer> < ...

  5. 洛谷 P1070 道路游戏(noip 2009 普及组 第四题)

    题目描述 小新正在玩一个简单的电脑游戏. 游戏中有一条环形马路,马路上有 nn个机器人工厂,两个相邻机器人工厂之间由一小段马路连接.小新以某个机器人工厂为起点,按顺时针顺序依次将这 nn个机器人工厂编 ...

  6. Angular.js思维导图

    AngularJS的四大特性的思维导图如下: 将AngularJS应用于工作:其思维导图如下: AngularJS服务思维导图:

  7. Python-11-循环

    x = 1 while x <= 100:     print(x)     x += 1   基本上, 可迭代对象是可使用for循环进行遍历的对象. numbers = [0, 1, 2, 3 ...

  8. MySQL的slave_exec_mode参数作用

    主从复制中常会遇到的问题就是1062主键重复 如果在读写分离的架构中,slave同步失败会对业务造成很大的影响的 因此,很有必要对主从复制做些监控,做些自动化的处理.涉及到MySQL的一个参数slav ...

  9. HDU-1281-棋盘游戏(最大匹配,枚举)

    链接:https://vjudge.net/problem/HDU-1281 题目: 小希和Gardon在玩一个游戏:对一个N*M的棋盘,在格子里放尽量多的一些国际象棋里面的“车”,并且使得他们不能互 ...

  10. 【NOI2014】起床困难综合症 贪心

    从高到低按位贪心,讨论一下初始0或1,分别暴力算出结果是什么 如果一开始0就能得1当然直接ans垒起来 如果1能得1而且当前m够用,那也垒起来,同时m减掉 否则gg 2min的代码 #include ...