Atitit json数据查询法 jsonpath 目录 1.1. 1.概述 1 1.2. 3.2。经营者特殊符号 1 1.3. # JSONPath expressions 2 1.4. Xpa

本文介绍了JSONPath,一种用于查询JSON数据的语言,类似于XML的XPath。内容包括:概述、运算符、表达式、与XPath的区别、使用示例、过滤器功能,以及函数和操作符的详细说明。
摘要由CSDN通过智能技术生成

Atitit json数据查询法  jsonpath

 

目录

1.1. 1.概述 1

1.2. 3.2。经营者特殊符号 1

1.3. # JSONPath expressions 2

1.4. Xpath vs jsonpath 4

1.4.2. Usage 5

1.5. Filters 5

1.6. 聚合运算3.3。功能和过滤器 9

1.7. jsonpath的函数 9

1.8. jsonpath 操作符 9

1.9. 与xpath对照 10

1.10. Javascript Example: 10

1.11. # Issues 11

 

    1. 1.概述

XML的优点之一是处理的可用性-包括XPath-它被定义为W3C标准。对于JSON,出现了一个类似的名为JSONPath的工具。

本文将介绍Jayway JsonPath,它是JSONPath规范的Java实现。它描述了设置,语法,通用API以及用例的演示。

    1. 3.2。经营者特殊符号

在JsonPath中,我们有几个有用的运算符:

根节点($):此符号表示JSON结构的根成员,无论它是对象还是数组。它的用法示例包含在前面的小节中。

当前节点(@):表示正在处理的节点,通常用作谓词的输入表达式的一部分。假设我们在上面的JSON文档中处理book数组,表达式book [?(@。price == 49.99)]引用该数组中的第一本书

通配符(*):表示指定范围内的所有元素。例如,book [*]表示book数组内的所有节点

$root.操作符或[]索引的方式获取指定 JsonPath 数据

    1. # JSONPath expressions

JSONPath expressions always refer to a JSON structure in the same way as XPath expression are used in combination with an XML document. Since a JSON structure is usually anonymous and doesn't necessarily have a "root member object" JSONPath assumes the abstract name $ assigned to the outer level object.

JSONPath expressions can use the dot–notation

$.store.book[0].title

or the bracket–notation

$['store']['book'][0]['title']

for input pathes. Internal or output pathes will always be converted to the more general bracket–notation.

JSONPath allows the wildcard symbol * for member names and array indices. It borrows the descendant operator '..' from E4X and the array slice syntax proposal [start:end:step] from ECMASCRIPT 4.

Expressions of the underlying scripting language (<expr>) can be used as an alternative to explicit names or indices as in

$.store.book[(@.length-1)].title

using the symbol '@' for the current object. Filter expressions are supported via the syntax ?(<boolean expr>) as in

$.store.book[?(@.price < 10)].title

Here is a complete overview and a side by side comparison of the JSONPath syntax elements with its XPath counterparts.

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值