11-29-2022 12:51 PM
Hi there, I am trying to check if json list has a node within.
in below json checking if IDOC.E1EDP01 has E1EDPT1; which works fine. then when I am trying to look for E1EDPT2, thats when its failing.
I have below expression.
$IDOC.E1EDP01.filter(x=>x.hasPath(‘E1EDPT1’)).length > 0 && jsonPath($, “IDOC.E1EDP01[*].E1EDPT1”).filter(x=>x.hasPath(‘E1EDPT2’)).length > 0
[
{
"IDOC": {
"E1EDP01": [
{
"POSEX": "00010",
"E1EDPT1": [
{
"E1EDPT2": [
{
"TDLINE": "CONTROL PANEL"
}
]
}
]
},
{
"POSEX": "00020",
"E1EDPT1": {
"E1EDPT2": [
{
"TDLINE": " TURBINE, DRAWING"
}
]
}
},
{
"POSEX": "00030",
"E1EDPT1": [
{
"E1EDPT2": [
{
"TDLINE": "CONTROLLER"
}
]
}
]
}
]
}
}
]
Any help in how I can achieve it?
Thanks
Manohar
11-29-2022 01:11 PM
Hey @manohar,
Are you checking for E1EDPT2 on a specific place (level) or anywhere in the object?
The following expression will return the value of E1EDPT2 if it’s on a specific location in the json
jsonPath($, "IDOC.E1EDP01[*].E1EDPT1.E1EDPT2")
And a similar one, will look for everywhere in the json after the E1EDP01[*].E1EDPT1
part :
jsonPath($, "IDOC.E1EDP01[*].E1EDPT1..E1EDPT2")
Note that this will result in array of values.
If this is not what you’re looking for, please give us some more specific information.
Regards,
Bojan
11-29-2022 01:49 PM
Hi @bojanvelevski, as always appreciate your help.
no I am just checking if E1EDPT2 exist or not and has value in it.
hope that helps.
Thanks
Manohar
11-29-2022 07:29 PM
I was able to just us your jsonPath($, “IDOC.E1EDP01[*].E1EDPT1…E1EDPT2”) and it worked just fine.
Thanks again @bojanvelevski for the help.
Is there way to mark a response as solution?
Manohar
11-29-2022 09:37 PM
Anytime. You should see the option on the response itself.