Use dynamic property to search for a value


Im trying to look for an object based on a property value. Im trying to it this way but it doesnt work. Any chance i can fetch this dynamically without hardcording?

edit : “value”:“&{data[?@[0]== property]}”

doesnt work as well as it returns an empty array but when i hardcode

“value”:“&{data[?@[0]== ‘description’]}” it works

I am looking for a similar solution.

How can we access a dynamic keyvalue and use that value as key selector from another array.

For example:

  "warehouse": "location4",
  "sites": {
    "location1": "3600",
    "location2": "3600",
    "location3": "3600",
    "location4": "1700"

&{sites[&{warehouse}]} == "1700"

But the above unfortunately does not work.
I also tried @brethren 's way finding a way to realise this with JMES path but no success yet.

Anyone that has an solution to our problems?

Unfortunately, it is not possible to use a variable expander inside another variable expander.

@brethren could you please provide us with the test data for your case?

@Rickvzanden For your case, we can do the steps below.

In the above approach, you can format the source property in a similar format as the property in which you want to search for the value. Then, we can do a key intersection between the two arrays/objects, and the result should be an array/object with the intersected key.

1 Like

Thank you for the quick reply and solution!
This was very helpful.

Any chance a variable inside a variable could become a feature in the future? Although this works fine, it looks a bit inefficient.