免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
kettle中json input中數(shù)據(jù)的解析
userphoto

2022.11.25 河北

關注
摘要:

與xml文檔中XPath的定位類似,JsonPath表達式通常用于檢索或設置Json路徑。使用。符號:$。百貨商

... 展開
一、對于json數(shù)據(jù)的解析 簡介
  • JSONPath - 是xpath在json的應用。

             類似于XPath在xml文檔中的定位,JsonPath表達式通常是用來路徑檢索或設置Json的。其表達式可以接受“dot–notation”和“bracket–notation”格式,例如$.store.book[0].title、$['store’]['book’][0]['title’]

  • JSONPath 表達式
  1. JSONPaht 用一個抽象的名字$來表示最外層對象。
  2. 使用.符號:$.store.book[0].title
  3. 使用[]:$['store']['book'][0]['title']
  4. 數(shù)組索引

1)JSONPath 允許使用通配符 * 表示所以的子元素名和數(shù)組索引。還允許使用 '..' 從E4X參照過來的和數(shù)組切分語法[start:end:step]

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

3)使用'@'符號表示當前的對象,?(<判斷表達式>) 使用邏輯表達式來過濾

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

二、JSONPath語法元素和對應XPath元素的對比

XPath

JSONPath

Description

/

$

表示根元素

.

@

 當前元素

/

. or []

子元素

..

n/a

父元素

//

..

遞歸下降,JSONPath是從E4X借鑒的。

*

*

通配符,表示所有的元素

@

n/a

 屬性訪問字符

[]

[]

子元素操作符

|

[,]

連接操作符在XPath 結(jié)果合并其它結(jié)點集合。JSONP允許name或者數(shù)組索引。

n/a

[start:end:step]

數(shù)組分割操作從ES4借鑒。

[]

?()

應用過濾表示式

n/a

()

腳本表達式,使用在腳本引擎下面。

()

n/a

Xpath分組

三、jsonpath使用舉例

        接口返回:

  1. [{
  2.              "id": "PRIMARY",
  3.              "name": "小學",
  4.              "front_id": "PRIMARY",
  5.              "front_name": "小學"
  6. }, {
  7.              "id": "JUNIOR",
  8.              "name": "初中",
  9.              "front_id": "JUNIOR",
  10.              "front_name": "初中"
  11. }, {
  12.              "id": "HIGH",
  13.              "name": "高中",
  14.              "front_id": "HIGH",
  15.              "front_name": "高中"
  16. }, {
  17.              "id": "TECHNICAL",
  18.              "name": "中專/技校",
  19.              "front_id": "TECHNICAL",
  20.              "front_name": "中專/技校"
  21. }, {
  22.              "id": "COLLEGE",
  23.              "name": "大專",
  24.              "front_id": "COLLEGE",
  25.              "front_name": "大專"
  26. }, {
  27.              "id": "BACHELOR",
  28.              "name": "本科",
  29.              "front_id": "BACHELOR",
  30.              "front_name": "本科"
  31. }, {
  32.              "id": "MASTER",
  33.              "name": "碩士",
  34.              "front_id": "MASTER",
  35.              "front_name": "碩士"
  36. }, {
  37.              "id": "DOCTOR",
  38.              "name": "博士",
  39.              "front_id": "DOCTOR",
  40.              "front_name": "博士"
  41. }]

JSONPath

結(jié)果


$.[*].name

所有學歷的name


$.[*].id

所有的id


$.[*]

所有元素


$.[(@.length-2)].name

倒數(shù)第二個元素的name


$.[2]

第三個元素


$.[(@.length-1)]

最后一個元素


$.[0,1]

$.[:2]

前面的兩個元素


$.[?(@.name =~ /.*中/i)]

 過濾出所有的name包含“中”的書。


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

過濾出價格低于10的書。


$.[*].length()

所有元素的個數(shù)

接口返回:

  1. {
  2.     "store": {
  3.         "book": [
  4.             {
  5.                 "category": "reference",
  6.                 "author": "Nigel Rees",
  7.                 "title": "Sayings of the Century",
  8.                 "price": 8.95
  9.             },
  10.             {
  11.                 "category": "fiction",
  12.                 "author": "Evelyn Waugh",
  13.                 "title": "Sword of Honour",
  14.                 "price": 12.99
  15.             },
  16.             {
  17.                 "category": "fiction",
  18.                 "author": "Herman Melville",
  19.                 "title": "Moby Dick",
  20.                 "isbn": "0-553-21311-3",
  21.                 "price": 8.99
  22.             },
  23.             {
  24.                 "category": "fiction",
  25.                 "author": "J. R. R. Tolkien",
  26.                 "title": "The Lord of the Rings",
  27.                 "isbn": "0-395-19395-8",
  28.                 "price": 22.99
  29.             }
  30.         ],
  31.         "bicycle": {
  32.             "color": "red",
  33.             "price": 19.95
  34.         }
  35.     },
  36.     "expensive": 10
  37. }

JsonPath表達式

結(jié)果

$.store.book[*].author 
或 
$..author

[
“Nigel Rees”,
“Evelyn Waugh”,
“Herman Melville”,
“J. R. R. Tolkien”
]

$.store.* 顯示所有葉子節(jié)點值

[
[
{
”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
}
]

$.store..price

[
8.95,
12.99,
8.99,
22.99,
19.95
]

$..book[0,1]

$..book[:2]

[
{
”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
}
]

$..book[-2:]

獲取最后兩本書

$..book[2:]

[
{
”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
}
]

$..book[?(@.isbn)]

所有具有isbn屬性的書

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

所有價格小于10的書

$..book[?(@.price <= $['expensive’])]

所有價格低于expensive字段的書

$..book[?(@.author =~ /.*REES/i)]

所有符合正則表達式的書 
[
{
”category” : “reference”,
”author” : “Nigel Rees”,
”title” : “Sayings of the Century”,
”price” : 8.95
}
]

$..*

返回所有

$..book.length()

[
4
]

四、過濾器

操作符

描述

==

等于符號,但數(shù)字1不等于字符1(note that 1 is not equal to '1’)

!=

不等于符號

<

小于符號

<=

小于等于符號

>

大于符號

>=

大于等于符號

=~

判斷是否符合正則表達式,例如[?(@.name =~ /foo.*?/i)]

in

所屬符號,例如[?(@.size in ['S’, 'M’])]

nin

排除符號

size

size of left (array or string) should match right

empty

判空符號

例如:

1)所有具有isbn屬性的書

$.store.book[?(@.isbn)].author

2)所有價格大于10的書

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

3)查詢xxx==3的所有對象

$.result.list[?(@.xxx ==3)]

4)可以自定義過濾器來獲取想要的任何元素,可以多條件查詢

五、在線解析器

http://jsonpath.com/

https://jsonpath.curiousconcept.com/

在這里,你可以將你的json格式的數(shù)據(jù)拷貝上去,自己手動寫表達式解析查看。

本站僅提供存儲服務,所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
技術必備:推薦一款接口自動化測試數(shù)據(jù)校驗神器
JMeter處理器09
json-path 解析json 類似xpath 超好用
python接口自動化39-JMESPath解析json數(shù)據(jù)
[精]XPath入門教程
python中的爬蟲神器 XPath 介紹
更多類似文章 >>
生活服務
分享 收藏 導長圖 關注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服