页面树结构

版本比较

标识

  • 该行被添加。
  • 该行被删除。
  • 格式已经改变。

...

JSONPath描述
$根对象或元素。
@当前对象或元素。
. or []

子元素操作符。

比如:$.store.book[0].title  $['store']['book'][0]['title']

..递归匹配所有子元素。
*通配符. 匹配所有对象或元素。
[]下标运算符,JsonPath索引从0开始。
[,]连接运算符,将多个结果拼成数组返回,JSONPath允许使用别名。
[start:end:step]数组切片运算符。
?()

过滤器(脚本)表达式。


(<expr>)脚本表达式。

要点:

1.  根对象使用 $ 来表示,而无需区分是对象还是数组。

...

    $.store.book[?(@.price < 10)].title 表示获取价格小于 10 的所有 book 的 title。


函数

函数描述输出类型

min()

对于一个数值型数组,找到最小值

双精度

max()

对于一个数值型数组,找到最大值

双精度

avg()

对于一个数值型数组,求平均值

双精度

stddev()

对于一个数值型数组,求标准差

双精度

length()

求数组的长度

整型

sum()

对于一个数值型数组,求总和

双精度


示例

例如有下面的json结构:

代码块
linenumberstrue
{
    "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
        }
    }
}