0
votes

I am trying to use Mule dataweave transformer to transform a JSON to an XML. One of the key name of the JSON payload is dynamic and it depends on the input you provide to the JSON payload. Please look at the line #40 where I am using

value: payload.quotes.INR.midpoint

to parse the data. INR is basically the target currency of the payload and the target currency value is line #39:

target_currency: payload.meta.effective_params.quote_currencies[0]

So while assigning the value I want to use something like this:

value: payload.quotes.($(payload.meta.effective_params.quote_currencies[0])).midpoint

Is this possible at all with Mulesoft dataweave transformer? Or, if not, then can you please suggest any neat solution?

1

1 Answers

4
votes

Yes it is, use square brackets [] to lookup the map by key:

exchange: {
        source_currency: payload.base_currency,
        target_currency: payload.meta.effective_params.quote_currencies[0],
        value: payload.quotes[payload.meta.effective_params.quote_currencies[0]].midpoint
    }