7)运行得到如下结果。
v10_1=4 v10_matchNr=1 v11_1=三只松鼠每日坚果 v11_matchNr=1 v12_1={"category":"零食","name":"黄飞鸿花生","desc":"黄飞红 麻辣花生210g*2袋 每日坚果炒货休闲网红囤货零食小吃下酒菜花生米","price":28.8} v12_matchNr=1 v1_1=黄飞鸿花生 v1_2=良品铺子 v1_3=三只松鼠每日坚果 v1_4=百草味 v1_matchNr=4 v2_1=[{"category":"零食","name":"黄飞鸿花生","desc":"黄飞红 麻辣花生210g*2袋 每日坚果炒货休闲网红囤货零食小吃下酒菜花生米","price":28.8},{"category":"零食","name":"良品铺子","desc":"良品铺子 经典坚果礼盒8袋装/1310g食食有爱 每日坚果干果休闲零食坚果炒货零食大礼包节日送礼夏威夷果核桃","date":"2022-2-4","price":108.0},{"category":"零食","name":"三只松鼠每日坚果","desc":"三只松鼠每日坚果 750g/30袋 中秋送礼坚果礼盒零食大礼包儿童孕妇节日混合干果腰果夏威夷果核桃仁开心果","price":149.0},{"category":"零食","name":"百草味","desc":"百草味 休闲零食小吃整箱蛋糕办公室早餐手撕面包点心传统糕点 原味肉松饼1000g/箱","price":34.9}] v2_2={"name":"全栈软件测试工程师宝典","author":"顾翔","price":168.0} v2_matchNr=2 v3_1=168.0 v3_2=[28.8,108.0,149.0,34.9] v3_matchNr=2 v4_1={"category":"零食","name":"三只松鼠每日坚果","desc":"三只松鼠每日坚果 750g/30袋 中秋送礼坚果礼盒零食大礼包儿童孕妇节日混合干果腰果夏威夷果核桃仁开心果","price":149.0} v4_matchNr=1 v5_1={"category":"零食","name":"三只松鼠每日坚果","desc":"三只松鼠每日坚果 750g/30袋 中秋送礼坚果礼盒零食大礼包儿童孕妇节日混合干果腰果夏威夷果核桃仁开心果","price":149.0} v5_matchNr=1 v6_1={"category":"零食","name":"黄飞鸿花生","desc":"黄飞红 麻辣花生210g*2袋 每日坚果炒货休闲网红囤货零食小吃下酒菜花生米","price":28.8} v6_2={"category":"零食","name":"良品铺子","desc":"良品铺子 经典坚果礼盒8袋装/1310g食食有爱 每日坚果干果休闲零食坚果炒货零食大礼包节日送礼夏威夷果核桃","date":"2022-2-4","price":108.0} v6_matchNr=2 v7_1={"category":"零食","name":"良品铺子","desc":"良品铺子 经典坚果礼盒8袋装/1310g食食有爱 每日坚果干果休闲零食坚果炒货零食大礼包节日送礼夏威夷果核桃","date":"2022-2-4","price":108.0} v7_matchNr=1 v8_1={"category":"零食","name":"三只松鼠每日坚果","desc":"三只松鼠每日坚果 750g/30袋 中秋送礼坚果礼盒零食大礼包儿童孕妇节日混合干果腰果夏威夷果核桃仁开心果","price":149.0} v8_2={"category":"零食","name":"百草味","desc":"百草味 休闲零食小吃整箱蛋糕办公室早餐手撕面包点心传统糕点 原味肉松饼1000g/箱","price":34.9} v8_matchNr=2 v9_1={"category":"零食","name":"良品铺子","desc":"良品铺子 经典坚果礼盒8袋装/1310g食食有爱 每日坚果干果休闲零食坚果炒货零食大礼包节日送礼夏威夷果核桃","date":"2022-2-4","price":108.0} v9_matchNr=1
8)同样将结果汇集以下。如表4所示。
表4 food.json JSON JMSPath提取器获取数据
JSON JMSPath |
值 |
含义 |
store.food[*].name |
var_1=黄飞鸿花生 var_2=良品铺子 var_3=三只松鼠每日坚果 var_4=百草味 var_matchNr=4 |
所有food的名称 |
store.* |
var_1=[{"category":"零食","name":"黄飞鸿花生","desc":"黄飞红麻辣花生210g*2袋每日坚果炒货休闲网红囤货零食小吃下酒菜花生米","price":28.8},{"category":"零食","name":"良品铺子","desc":"良品铺子经典坚果礼盒8袋装/1310g食食有爱每日坚果干果休闲零食坚果炒货零食大礼包节日送礼夏威夷果核桃","date":"2022-2-4","price":108.0},{"category":"零食","name":"三只松鼠每日坚果","desc":"三只松鼠每日坚果 750g/30袋中秋送礼坚果礼盒零食大礼包儿童孕妇节日混合干果腰果夏威夷果核桃仁开心果","price":149.0},{"category":"零食","name":"百草味","desc":"百草味休闲零食小吃整箱蛋糕办公室早餐手撕面包点心传统糕点原味肉松饼1000g/箱","price":34.9}] var_2={"name":"全栈软件测试工程师宝典","author":"顾翔","price":168.0} var_matchNr=2 |
store包含的所有分类数据 |
store.[book.price,food[*].price] |
var_1=168.0 var_2=[28.8,108.0,149.0,34.9] var_matchNr=2 |
所有商品的价格 |
store.food [2] |
var_1={"category":"零食","name":"三只松鼠每日坚果","desc":"三只松鼠每日坚果 750g/30袋中秋送礼坚果礼盒零食大礼包儿童孕妇节日混合干果腰果夏威夷果核桃仁开心果","price":149.0} var_matchNr=1 |
标号为2的food数据(从0开始) |
store.food [-2] |
var_1={"category":"零食","name":"三只松鼠每日坚果","desc":"三只松鼠每日坚果 750g/30袋中秋送礼坚果礼盒零食大礼包儿童孕妇节日混合干果腰果夏威夷果核桃仁开心果","price":149.0} var_matchNr=1 |
倒数第2个food数据 |
store.food [:2] |
var_1={"category":"零食","name":"黄飞鸿花生","desc":"黄飞红麻辣花生210g*2袋每日坚果炒货休闲网红囤货零食小吃下酒菜花生米","price":28.8} var_2={"category":"零食","name":"良品铺子","desc":"良品铺子经典坚果礼盒8袋装/1310g食食有爱每日坚果干果休闲零食坚果炒货零食大礼包节日送礼夏威夷果核桃","date":"2022-2-4","price":108.0} var_matchNr=2 |
前2个food的数据 |
store.food [1:2] |
var_1={"category":"零食","name":"良品铺子","desc":"良品铺子经典坚果礼盒8袋装/1310g食食有爱每日坚果干果休闲零食坚果炒货零食大礼包节日送礼夏威夷果核桃","date":"2022-2-4","price":108.0} var_matchNr=1 |
索引1(包括)到索引2(不包括)的food的数据 |
store.food [-2:] |
var_1={"category":"零食","name":"三只松鼠每日坚果","desc":"三只松鼠每日坚果 750g/30袋中秋送礼坚果礼盒零食大礼包儿童孕妇节日混合干果腰果夏威夷果核桃仁开心果","price":149.0} var_2={"category":"零食","name":"百草味","desc":"百草味休闲零食小吃整箱蛋糕办公室早餐手撕面包点心传统糕点原味肉松饼1000g/箱","price":34.9} var_matchNr=2 |
最后2个food的数据 |
store.food [?(@.date)] |
var_1={"category":"零食","name":"良品铺子","desc":"良品铺子经典坚果礼盒8袋装/1310g食食有爱每日坚果干果休闲零食坚果炒货零食大礼包节日送礼夏威夷果核桃","date":"2022-2-4","price":108.0} var_matchNr=1 |
包含date属性的数据 |
length(store.food [*]) |
var_1=4 var_matchNr=1 |
所有food种类的数量 |
max_by(store.food, &price).name |
var_1=三只松鼠每日坚果 var_matchNr=1 |
价格最高的food名称 |
min_by(store.food, &price) |
var_1={"category":"零食","name":"黄飞鸿花生","desc":"黄飞红麻辣花生210g*2袋每日坚果炒货休闲网红囤货零食小吃下酒菜花生米","price":28.8} var_matchNr=1 |
价格最低的food信息 |
最后我们对比一下JSON JMESPath Extractor与JOSN提取器。
- 一个JOSN提取器可以通过英文分号分离的方式,提取多个变量表达式。
- JSON JMESPath Extractor一次只可以提取一个变量,如果要提取多个变量,那么就需要添加多个JSON JMESPath Extractor。
- JOSN提取器不支持函数,JSON JMESPath Extractor支持使用函数length()、max_by()和min_by()。