I have a json like below:
[
{
"skuId": "1234",
"plans": [
{
"plan": {
"planName": "plan1",
"planId": "abcd1231",
}
},
{
"plan": {
"planName": "plan2",
"planId": "loks3123",
}
}
]
},
{
"skuId": "5341",
"plans": [
{
"plan": {
"planName": "plan3",
"planId": "awer3234",
}
},
{
"plan": {
"planName": "plan4",
"planId": "gefd4231",
}
}
]
},
{
"skuId": "7649",
"plans": [
{
"plan": {
"planName": "plan5",
"planId": "kitv5397",
}
}
]
}
]
Now i have a planId "loks3123", and i want to get the skuId where it belongs to. In this case planId "loks3123" belongs to skuId "1234".
Is it possible using JsonPath to do that? If so, How to do that using JsonPath? If not, what should i do?
Thanks!
You need to find a node containing a plans attribute that contains a planId attribute that matches your text. Using the suggestion at the end of https://github.com/json-path/JsonPath/issues/287 you can get what you want with:
$..[?(@.plans[?(@.plan.planId == 'abcd1231')] empty false)].skuId
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With