Jsonpath的基本使用
JSONPath - 是xpath在json的应用。
JSONPath 表达式
$.store.book[0].title
$['store']['book'][0]['title']
[start:end:step]是从ECMASCRIPT 4 参照过来的。$.store.book[(@.length-1)].title
$.store.book[?(@.price < 10)].title
| XPath | JSONPath | Description |
| / | $ | 表示根元素 |
| . | @ | 当前元素 |
| / | . or [] | 子元素 |
| .. | n/a | 父元素 |
| // | .. | 递归下降,JSONPath是从E4X借鉴的。 |
| * | * | 通配符,表示所有的元素 |
| @ | n/a | 属性访问字符 |
| [] | [] |
子元素操作符
|
| | | [,] |
连接操作符在XPath 结果合并其它结点集合。JSONP允许name或者数组索引。
|
| n/a | [start:end:step] |
数组分割操作从ES4借鉴。
|
| [] | ?() |
应用过滤表示式
|
| n/a | () |
脚本表达式,使用在脚本引擎下面。
|
| () | n/a | Xpath分组 |
- []在xpath表达式总是从前面的路径来操作数组,索引是从1开始。
- 使用JOSNPath的[]操作符操作一个对象或者数组,索引是从0开始。
SONPath 例子
{ "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 | 结果 |
/store/book/author |
$.store.book[*].author |
书点所有书的作者
|
//author |
$..author |
所有的作者
|
/store/* |
$.store.* |
store的所有元素。所有的bookst和bicycle
|
/store//price |
$.store..price |
store里面所有东西的price
|
//book[3] |
$..book[2] |
第三个书
|
//book[last()] |
$..book[(@.length-1)] |
最后一本书 |
//book[position()<3] |
$..book[0,1]
$..book[:2] |
前面的两本书。 |
//book[isbn] |
$..book[?(@.isbn)] |
过滤出所有的包含isbn的书。 |
//book[price<10] |
$..book[?(@.price<10)] |
过滤出价格低于10的书。 |
//* |
$..* |
所有元素。
|
这就是jsonpath的基本使用
xpath:https://www.cnblogs.com/mswyf/p/9337734.html
Jsonpath的基本使用的更多相关文章
- restassured - JsonPath
https://github.com/rest-assured/rest-assured/blob/master/json-path/src/test/java/io/restassured/path ...
- jsonpath
1. java 类库 jayway/JsonPath maven 使用方法 <dependency> <groupId>com.jayway.jsonpath</grou ...
- 使用jsonpath解析json内容
JsonPath提供的json解析非常强大,它提供了类似正则表达式的语法,基本上可以满足所有你想要获得的json内容.下面我把官网介绍的每个表达式用代码实现,可以更直观的知道该怎么用它. 一.首先需要 ...
- 好用的json-path
$.store.book[?(@.price < 10)].title Here is a complete overview and a side by side comparison of ...
- JsonPath详解
JsonPath is to JSON what XPATH is to XML, a simple way to extract parts of a given document. JsonPat ...
- 一.HttpClient、JsonPath、JsonObject运用
HttpClient详细应用请参考官方api文档:http://hc.apache.org/httpcomponents-client-4.5.x/httpclient/apidocs/index.h ...
- jsonpath读取json数据格式公用方法!!!
import java.util.LinkedHashMap; import com.jayway.jsonpath.JsonPath; import com.jayway.jsonpath.Pred ...
- Python爬虫(十六)_JSON模块与JsonPath
本篇将介绍使用,更多内容请参考:Python学习指南 数据提取之JSON与JsonPATH JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,它是的人们很容易 ...
- JSONPath使用
JSONPath是fastjson在1.2.0之后支持的.JSONPath是一个很强大的功能.关于JSONPath的介绍请查看官方文档 JSONPath. 官方文档上给出了详细的说明以及使用.但是官方 ...
- Python_实现json数据的jsonPath(精简版)定位及增删改操作
基于python实现json数据的jsonPath(精简版)定位及增删改操作 by:授客 QQ:1033553122 实践环境 win7 64 Python 3.4.0 代码 #-*- encod ...
随机推荐
- /src/struts.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC ...
- 搭建GitLab+Jenkins
1. Jenkins and GitLab Jenkins是一个自动化服务器,可以运行各种自动化构建.测试或部署任务. GitLab是一个代码仓库,用来管理代码. 两者结合起来,就可以实现开发者提交代 ...
- ArrayList删除--------ConcurrentModificationException问题
在做项目中用到List存储数据,在里面做数据操作时候用到了删除.结果抛出ConcurrentModificationException异常.在这里把问题总结一下. 原因: ArrayList进行for ...
- ajax-》post
1:最近写完前端,又写后端,jQuery的ajax已经用烂了,事实证明的确好用,再分享一下. data是后台echo的值,可以是数字,也可以是数组,用json_encode()包裹数组形式,前端接收要 ...
- mongo的csv文件参考
https://blog.csdn.net/u012318074/article/details/77713228
- org注释包
1.注释包 物种 OrgDB 按蚊(Anopheles) org.Ag.eg.db 拟南芥(Arabidopsis) org.At.tair.db 牛(Brovine) org.Bt.eg.db 蠕虫 ...
- JMeter学习(十五)JMeter测试Java(转载)
转载自 http://www.cnblogs.com/yangxia-test 目的:对Java程序进行测试 目录 一.核心步骤 二.实例 三.JMeter Java Sampler介绍 四.自带Ja ...
- 【Spider】学习使用XMLFeedSpider
前面写了学习CrawlSpider遇到的问题后,今天学XMLFeedSpider又出现了启动后没爬取到数据,但又不报错的情况 经过排查,发现又是一个粗心大意的错误: class SpiderUserX ...
- 【pycharm】使用过程的相关问题
背景:安装scrapy后在cmd里可以正常import scrapy模块,但是在pycharm里不可以(python2.7) 问题:cmd中能正常导入模块,在pycharm报错 原因:pycharm里 ...
- Java Web开发和Python Web开发之间的区别
今天的文章讨论了Java Web开发和Python Web开发之间的区别.我不鼓励我们在这里从Java Web迁移到Python Web开发.我只是想谈谈我的感受.它不一定适合所有情况,仅供我们参考. ...