jsonpath

一、jsonpath是什么?
二、如何使用?


image.png

三、实践
1.$.filed1.field2

from jsonpath_ng import jsonpath,parse

json_str = {"data":{
        "ecifId":"2022100400000103",
        "operationId":"1628612966502549718749141715287189397281668389298609270",
        "operationStatus":100,
        "pinSetedFlag":"1",
        "securityMethods":[]
    },
    "success":True}

expre_str = parse('$.data.operationStatus')
data = expre_str.find(json_str)
print("operationStatus:",data[0].value)
image.png

2.$.field1[*].id
获取列表中的所有

json_str1 = data = { "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
    }
  }
}

expre_str = parse('$.store.book[*].price')
data = expre_str.find(json_str1)
prices = [d.value for d in data]
print(prices)
image.png
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容