Home > database >  Filter nested JSON object using JSONPath with Condition
Filter nested JSON object using JSONPath with Condition

Time:09-15

I have a below json object and need to get only c_Internet child object with a condition where the PIID is having value "1234567".

{
  "OrderComponentInfo": {
    "members": {
      "ADD": {
        "DIA": [
          {
            "c_Internet": {
              "PIID": "1234567",
              "IPv6_Multiple_Path_Needed": ""
            },
            "Test": {
              "PIID": "1234567",
              "INT_Acc_MSP_ID": "",
              "ConnectedService": "INTERNET"
            }
          },
          {
             "c_Internet": {
              "PIID": "7658964",
              "IPv6_Multiple_Path_Needed": ""
            },
            "Test": {
              "PIID": "7658964",
              "INT_Acc_MSP_ID": "",
              "ConnectedService": "INTERNET"
            }
          }
        ]
      }
    }
  }
}

I trued below query but dint work

$..ADD.DIA[?(@.PIID = "1234567")][['c_Internet']]

Thanks in advance.

CodePudding user response:

you have to use c_Internet.PIID not just PIID

$..ADD.DIA[?(@.c_Internet.PIID == "1234567" )]["c_Internet"]

result

[
  {
    "PIID": "1234567",
    "IPv6_Multiple_Path_Needed": ""
  }
]
  • Related