如何使用 JSON 文档中的值进行 JSONPath 查询

问题描述 投票:0回答:1

我有以下 JSON:

{
    "person": {
        "id": "5678"
    },
    "result": {
        "accounts": [
            {
                "id": "1234",
                "details": [
                    {
                        "name": "abcd"
                    }
                ]
            },
            {
                "id": "5678",
                "details": [
                    {
                        "name": "efgh"
                    }
                ]
            }
        ]
    }
}

我需要根据“person”属性中的“id”找到帐户。我尝试了以下操作: $..accounts[[电子邮件受保护] == $.person.id]] 它什么也没有返回。 任何帮助将不胜感激

我尝试过: $..accounts[[电子邮件受保护] == $.person.id]]

我期待以下结果:

{
    "id": "5678",
    "details": [
        {
            "id": "5678",
            "name": "efgh"
        }
    ]
}
jsonpath json-path-expression
1个回答
0
投票

您的路径尽头有一个额外的

]
。当我跑步时

$..accounts[[email protected] == $.person.id]

在我的操场上,https://json-everything.net/json-path,它按预期工作并返回:

[
  {
    "Value": {
      "id": "5678",
      "details": [
        {
          "name": "efgh"
        }
      ]
    },
    "Location": "$['result']['accounts'][1]"
  }
]
© www.soinside.com 2019 - 2024. All rights reserved.