-1

For a given payload:

{
"a": "Hello world"
}

and a variable: var test = {"b": "a"}

I would like to get "Hello world" using the variable test's key, "b".

I tried payload.(test."b") and does not work.

Mio Figlio
  • 11
  • 4
  • This question is a duplicate. Please search previous questions. – aled Nov 22 '22 at 16:43
  • 1
    Does this answer your question? [Mule 4: Dataweave: Query a key dynamically based on a value](https://stackoverflow.com/questions/71647552/mule-4-dataweave-query-a-key-dynamically-based-on-a-value) – aled Nov 22 '22 at 16:44

1 Answers1

-1

You can achieve this using dynamic selectors.

%dw 2.0
output application/json
var test = {"b": "a"}
---
payload[test.b]