添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

python jsonpath-ng examples

jsonpath-ng是一个python库,允许你使用JSONPath语法提取JSON数据。

下面是一些简单的例子:

import json
from jsonpath_ng import jsonpath, parse
# 要提取的JSON数据
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
# 解析JSONPath表达式
expression = parse('$.store.book[*].author')
# 提取数据
result = [match.value for match in expression.find(data)]
print(result)
# 输出:['Nigel Rees', 'Evelyn Waugh']

这仅仅是一个简单的例子,您可以找到更多的例子和详细的文档,以了解如何使用jsonpath-ng。

  •