0

Following is my json data

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

Now I want to extract "alias" value based on condition based fullname value from this json data using jsonpath.

I am using following expression but failed to parse result

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

1 Answers1

2

Your JSON is malformed, if it really looks like you posted - you won't be able to use JSON Extractor, you will have to switch to Regular Expression Extractor.

Valid JSON would be something like:

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

And if it is correct your JsonPath expression works fine as it evidenced by JsonPath Tester mode of the View Results Tree listener:

enter image description here

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • I am getting following error when running `Exception: Could not compile inline filter : [?(@.name.fullname == "fullname1")]` – Nirmal Baral Nov 05 '19 at 09:40