$.store.book[?(@.category=='fiction')].category
表达式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
}
]
随机推荐
- I.MX6 Android 永不休眠
/************************************************************************* * I.MX6 Android 永不休眠 * 说明 ...
- Chrome focus样式
-webkit-box-shadow: 0 0 0 1000px #131313 inset;//获取焦点时候可以去除背景色 -webkit-text-fill-color: #fff;//字体颜色
- bzoj 4816 数字表格 —— 反演
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4816 推导过程同:http://www.cnblogs.com/zhouzhendong/p ...
- RabbitMQ队列,Redis\Memcached缓存
RabbitMQ RabbitMQ是一个在AMQP基础上完整的,可复用的企业消息系统. MQ全称Message Queue,消息队列(MQ)是一种应用程序对应用程序的通信方式.应用程序通过读写出入队列 ...
- Python 二维列表
一维列表,可以使用 * 快速创建list1=[0]*Width r = [0]*5 print r r[1]= 1 print r [0, 0, 0, 0, 0] [0, 1, 0, 0, 0] 扩展 ...
- JS开发中的一些小技巧和方法
生成指定范围内的随机数 当我们需要获取指定范围(min,max)内的整数的时候,下面的代码非常适合:这段代码用的还挺多的. function setRadomNum(min,max){ return ...
- Spring整合JUnit4测试时,使用注解引入多个配置文件
转自:https://blog.csdn.net/pwh309315228/article/details/62226372 一般情况下: @ContextConfiguration(Location ...
- Android精品资源汇总,10个源码(持续更新)
最近一直在学习Android,在各大社区逛,总结下自己看到的一些不错的源码.希望可以给大家带来帮助. 1.Android精品源码:带动态效果的Button(按钮) 最喜欢各种效果的按钮了,没办法就是这 ...
- linux命令-vim一般模式下光标移动
vim 有一般模式,编辑模式,命令模式 ///////一般模式可以光标移动,复制,剪切,粘贴 编辑模式可以输入想输入的字符 命令模式刚才用到了set nu //////////// ...
- vue.js 使用高德地图
1.获取key值 注册成为高德开发者需要分三步: 第一步,注册高德开发者: 第二步,去控制台创建应用: 第三步,获取Key 2.修改配置文件 webpack.base.conf.js externa ...