How to get the parent elements by quering the child elements in the json data.Explanation is given below

114 Views Asked by At

I am new to Apigee,I had tried a query to extract the value from the json data child and i need to get the parent element from the json data.

JSON is Here:

{ "Booksstall": [
        { "serialId": "10123456",
            "Name": "magic"
            "books": [
                { "Order": 3,
                    "Name": "Supermax"
                }
            ],
            "NormalserialIds": [
                {"serialId": "1234556",
                    "Status": "InStock",
                    "books": [
                        {"type": "400001623",
                            "Code": "PATR"
                        }
                    ]
                },
                {"serialId": "789101",
                    "Status": "OutoffStock",
                    "books": [
                        {"type": "400001623",
                            "Code": "NFES"
                        }
                    ]
                }
            ]
        }
    ]
}

I tried this query in online json validator ,but if I tried same in the Apigee extract variable policy by doing substitution Its not returning me any values.

$.Booksstall[?(@.NormalserialIds[0].serialId=="1234556")].serialId

The above query result is: 10123456.

Please suggest how can I try this.

1

There are 1 best solutions below

0
On

You can also use Javascript Policy to extract same. It should be simple and straight forward with Javascript Policy.

Cheers,

Anil Sagar