表达式1

$.store.book[?(@.category=='fiction')].category

json source

{
"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
}
},
"expensive": 10
}

返回

[
"fiction",
"fiction",
"fiction"
]

表达式2

$.store.book[?(@.category=='fiction')].title[1]

返回

[
"w",
"o",
"h"
]

表达式3

返回索引

$.store.book[0]

$.store.book

$.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
}
]
]

$.store.book[2]

谓词修饰

Inline Predicates

Inline predicates are the ones defined in the path.

List<Map<String, Object>> books =  JsonPath.parse(json)
.read("$.store.book[?(@.price < 10)]");

You can use && and || to combine multiple predicates [?(@.price < 10 && @.category == 'fiction')] , [?(@.category == 'reference' || @.price > 10)].

You can use ! to negate a predicate [?(!(@.price < 10 && @.category == 'fiction'))].

表达式5  枚举

$.store.book[?(@.category=='fiction')].author

返回:

[
"Evelyn Waugh",
"Herman Melville",
"J. R. R. Tolkien"
]

表达式6:作用域修饰

$.store.book[?(@.price < 10 && @.category == 'fiction')]

返回:

[
{
"category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick",
"isbn": "0-553-21311-3",
"price": 8.99
}
]
$.store.book[?(@.category == 'reference' || @.price > 10)]

返回:

[
{
"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": "J. R. R. Tolkien",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"price": 22.99
}
]
$.store.book[?(!(@.price < 10 && @.category == 'fiction'))]

返回:

[
{
"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": "J. R. R. Tolkien",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"price": 22.99
}
]

price 作用域大于10

作用域!

$.store.book[?((@.price < 10 && @.category == 'fiction'))]

返回:

[
{
"category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick",
"isbn": "0-553-21311-3",
"price": 8.99
}
]

解析{} 也就是: {子集合

$.[*]

返回:

[
{
"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
}
},
10,
[
{
"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
}
],
{
"color": "red",
"price": 19.95
},
{
"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
},
"reference",
"Nigel Rees",
"Sayings of the Century",
8.95,
"fiction",
"Evelyn Waugh",
"Sword of Honour",
12.99,
"fiction",
"Herman Melville",
"Moby Dick",
"0-553-21311-3",
8.99,
"fiction",
"J. R. R. Tolkien",
"The Lord of the Rings",
"0-395-19395-8",
22.99,
"red",
19.95
]

解析

$.[*].price

返回

[
19.95,
8.95,
12.99,
8.99,
22.99
]

混合表达式:

[?(@.firstname == 'Bob' || @.firstname == 'Jane' && @.surname == 'Smith')]"

拆分{}

$.store.[?(@.color)]

返回>>>:

[
{
"color": "red",
"price": 19.95
}
]

json通过正则过滤

$..book[?(@.author =~ /.*Melville/i)]

返回表达式:

http://jsonpath.herokuapp.com/?path=$..book[?(@.author =~ /.*REES/i)]
[
{
"category" : "fiction",
"author" : "Herman Melville",
"title" : "Moby Dick",
"isbn" : "0-553-21311-3",
"price" : 8.99
}
]
$..book[?(@.author =~ /.*/i)]

返回所有node节点

[
{
"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
}
]

特定未节点返回

http://jsonpath.herokuapp.com/?path=$..book[?(@.price =~ /.*99/i)]
$..book[?(@.price =~ /.*99/i)]
[
{
"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
}
]

随机推荐

  1. 【遍历二叉树】04二叉树的层次遍历【Binary Tree Level Order Traversal】

    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 给定一个二叉树,返回他的层次遍历的 ...

  2. P2P流媒体开源项目介绍

    P2P流媒体开源项目介绍1. PeerCast 2002年成立,最早的开源P2P流媒体项目.PeerCast把节点按树结构组织起来, 每个频道都是一个树, 直播源是根节点,父节点只给子节点提供数据.节 ...

  3. SparkWriteToHFile

    1. HFile的LoadIncrement卡住 原来是因为权限,我一直以为,load函数之后是要删除文件的,但是hdfs://slave1:8020/test/info文件夹所有的是只读权限,而且考 ...

  4. BZOJ5289:[HNOI2018]排列

    我对贪心的理解:https://www.cnblogs.com/AKMer/p/9776293.html 题目传送门:https://www.lydsy.com/JudgeOnline/problem ...

  5. bzoj 2096 [POI2004]ZAW——二进制枚举

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2069 可以把直接相连的点分成  从1点出的一部分  和  走向1点的一部分.多起点最短路就和 ...

  6. Python:str.ljust()、str.rjust()、str.center()函数

    str.ljust().str.rjust().str.center()函数 功能:调整字符串站位宽度,并确定字符串对齐方式: #可以用其它字符填充字符: #字符串长度 = 字符串个数(包含空格.标点 ...

  7. js点滴知识(1) -- 获取DOM对象和编码

    在今天的工作中发现了一些小的问题,在网上查了一下,才知道自己的js才是冰山一角,以后要虚心向他人学习,要虚怀若谷. 发现一:js获取DOM对象与jquery的区别 先前总以为,二者是一样的,最近才知道 ...

  8. hibernate 数据关联多对多

    多对多,必须有一张关系表来维持关系 数据库student,teacher student_teacher 三张表 但是在pojo中只需要建立student和teacher两个类,除非关系表也代表某种业 ...

  9. window下git,TortoiseGit安装,以及和github托管项目

    下载地址:http://msysgit.github.io/,安装时最好是先装git,再安装TortoiseGit. 一.git安装 1.第一步 2.第二步 3.第三步 4.第四步 5.第五步 6.第 ...

  10. linux命令-vim命令模式

    编辑模式下 按 “esc” 进去命令模式 :wq 保存并退出 :w  保存 已写入 :q!不保存强制退出 :wq! 强制保存退出 :set nu 显示行号 :set nonu 去掉行号 :nohl 取 ...