cancel
Showing results for 
Search instead for 
Did you mean: 

Perform a look up on keys of an object to get it's value

aspanda
New Contributor II

Hello All,

I have a requirement to extract values of an object based on it’s key through a lookup.

For Example i have following json structure :

{
“A”:{
“B” : {“value” :“test”},
“C” : {“value” :“test”},
“D” : {“value” :“test”},
“E” : {“value” :“test”},
}
A,B,C,D,E all are objects.

i want to extract only B’s value when the key matches to B.

Regards,
Asheerbad

5 REPLIES 5

tstack
Former Employee

You can use bracket notation to do a lookup based on the value of an expression:

$A[$keyToLookup]

So, if $keyToLookup contained “B”, the above expression would drill down into the “A” object and get the value of the property named “B” .