使用jsonpath提取json中的元素值

以下是我的json数据

{
    "primary": [
        {
            "secondary": {
                "name": {
                    "fullname": "fullname1"
                },"alias": "alias1"
            },"reference": "reference1"
        },{
            "secondary": {
                "name": {
                    "fullname": "fullname2"
                },"alias": "alias2"
            },"reference": "reference2"
        }
    ]
}

现在,我想使用jsonpath根据此json数据中基于条件的全名值提取“别名”值。

我正在使用以下表达式,但无法解析结果

  

$。primary [*]。secondary [?(@。name.fullname ==“ fullname1”)]。alias

guyouyan 回答:使用jsonpath提取json中的元素值

您的JSON格式不正确,如果确实看起来像您发布的一样-您将无法使用JSON Extractor,则必须切换到Regular Expression Extractor

有效的JSON类似于:

{
  "primary": [
    {
      "secondary": {
        "name": {
          "fullname": "fullname1"
        },"alias": "alias1"
      },"reference": "reference1"
    },{
      "secondary": {
        "name": {
          "fullname": "fullname2"
        },"alias": "alias2"
      },"reference": "reference2"
    },{
      "type": "online"
    }
  ]
}

如果正确,JsonPath可以证明您的JsonPath Tester mode of the View Results Tree listener表达式可以正常工作:

enter image description here

本文链接:https://www.f2er.com/3161009.html

大家都在问