当前位置:网站首页>JSON path syntax introduction and usage scenarios
JSON path syntax introduction and usage scenarios
2022-07-19 14:06:00 【Light rain youth】
List of articles
One 、 What is? JSON Path
JSONPath To JSON, as XPath To XML.JSONPath It's convenient for JSON Data structure for content extraction .
Here's a JSON Path Examples of grammar :
$.store.book[0].title
Two 、 Grammar introduction
| JsonPath | explain |
|---|---|
$ | Document root element |
@ | The current element |
. or [] | Match subordinate elements |
N/A | Match parent element ,JsonPath This operator is not supported |
.. | Recursively matches all child elements |
* | wildcard , Match subordinate elements |
N/A | Match the attributes ,JsonPath This operator is not supported |
[] | Subscript operator , Get elements from index ,XPath Index from 1 Start ,JsonPath Index from 0 Start |
[,] | Join operators , Concatenate multiple results into an array to return , You can use indexes or aliases |
[start:end:step] | Data slicing operation ,XPath I won't support it |
?() | Filter expression |
() | Script expressions , Using the underlying script engine ,XPath I won't support it |
N/A | grouping ,JsonPath I won't support it |
This is a very classic case , You can introduce in almost any JSON Path Where you see it , But it's practical .
{
"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
}
}
}
Example of cooperation , Corresponding to the syntax of the above table , The following examples are better understood .
| JsonPath | Result |
|---|---|
$.store.book[*].author | all book Of author node |
$..author | all author node |
$.store.* | store All nodes under ,book Array and bicycle node |
$.store..price | store All under price node |
$..book[2] | Matching first 3 individual book node |
$..book[(@.length-1)], or $..book[-1:] | Match the penultimate 1 individual book node |
$..book[0,1], or $..book[:2] | Match the first two book node |
$..book[?(@.isbn)] | Filter containing isbn Field node |
$..book[?(@.price<10)] | Filter price<10 The node of |
$..* | Recursively match all child nodes |
This address can be run online http://jsonpath.com/
3、 ... and 、 Where can I use it ?
It doesn't make much sense to have grammar alone , So where can I use JSON Path Well ?
1. Java
Jayway JsonPath , For reading JSON Document Java DSL.
Project address : https://github.com/json-path/JsonPath
2. PHP
JsonPath,JsonPath Of PHP Realization .
Project address : https://github.com/Galbar/JsonPath-PHP
3. JavaScript
jsonpath, Use JSONPath Expression query JavaScript object . be used for Node.js A powerful / Safe JSONPath engine .
Project address : https://github.com/dchester/jsonpath
4. Python
jsonpath-ng, Designed to meet the standard Python JSONPath The ultimate realization of , Including arithmetic and binary comparison operators , And provide clear AST.
Project address :https://pypi.org/project/jsonpath-ng/
5. Go
Jsonpath,JsonPath Of PHP Realization .
Project address :https://github.com/yalp/jsonpath
Four 、 summary
JSON Path As a grammatical standard , Realized with JSON Convenient reading . in addition , All kinds of languages JSON Path The names of the implemented projects are similar .
边栏推荐
- JSON Path 语法介绍和使用场景
- Start from here by counting the information of the broadcast room
- topy库的安装(拓扑优化软件)
- 国内外十大erp软件系统排名!
- Several small open source projects of mine over the years
- [postgraduate entrance examination vocabulary training camp] day 6 - eventually, state, create, productivity, stimulate
- 关于数据字典的一些解惑
- 类3实践
- NO.4位、字节、信息存储
- 毕设-基于SSM在线预约挂号系统
猜你喜欢

版本通告|Apache Doris 1.1 Release 版本正式发布!

Interview with Android development companies, make these three preparations and plan yourself

负载均衡有哪几种实现方式?

类3实践

关于数据字典的一些解惑
![[dynamic programming] - longest ascending subsequence model](/img/4c/dd54fcb8e3020bbf477cd62a410409.png)
[dynamic programming] - longest ascending subsequence model

FreeRTOS个人笔记-支持多优先级

「技术播客月」Day 10: Meta Podcast: 聊聊播客这件事

No.2 compilation preliminary

No.6 representation and operation of floating point numbers
随机推荐
Some common operation commands of the command line and solutions to common errors
Template virtual machine environment preparation
研二非科班研究生如何备战秋招
SSH keyless login
NO.5整数的表示与运算
No.4 bits, bytes, information storage
Ranking of top ten ERP software systems at home and abroad!
"Podcast" \ # 392 original Tang Lang original food: MIDSUMMER night, ma Sha, kebab, Kebab
STL string output and modification
[Flink] Flink will report an error if it fails to set checkpoints once. Setlerablecheckpointfailurenumber does not work
Introduction:Multiple DataFrames
Comprehensive analysis of C language multimedia open source framework GStreamer
QT use qlisview to realize QQ login history list
Helloword and led: a quick start to Hongmeng device development -- Huawei cloud 14 day Hongmeng device development practical learning notes Chapter 2
asterisk: rejected because extension not found in context ‘from-ipphone‘
unity 字幕滚动
Elastic load balancing automatically distributes the access traffic to multiple cloud servers, expands the external service capacity of the application system, and improves the security of the applica
[code shoe set novice village question 600] for the formatting control of strings, that is, the width and accuracy of strings
【6.15】Codeforces Round #798 (Div. 2)
No.3汇编进阶