Forum Discussion
aspanda
6 years agoNew Contributor II
Yes all B,C,D,E objects are keys with in Object A. I forgot the closing brces for object A in above example.
- cjhoward186 years agoEmployee
the expression:
$.hasPath("[*].B") ? jsonPath($, '[*].B') : "B Not Found"
is a bit more generic, and every object in the input doc must have the ‘B’ or hasPath will return false, but this will collect Every B’s value for each Object in the input doc if there is more than one.
For your case if the object you are going to be looking at is always just going to be A. Then this will work and is more specific:
$.hasPath("A.B") ? $A.B : "B Not Found"
This will return either the value if found, or the default string ‘B Not Found’, which can be changed to whatever you’d like
Hope this solves your use case, let me know if not.