Dynamic Key Value Pair in DataWeave
<p>DataWeave doesn't like what I'm trying to do with it, and I'm not sure if I'm doing something wrong, or if it is a limitation of DataWeave that isn't possible.</p>

<p>Here's the scenario: I'm querying Salesforce and getting two values back: lets call them X and Y.</p>

<p>Here's the return I want <code>[{X:Y}, {X2:Y2}, {X3:Y3}, ...]</code> however, using DataWeave it doesnt seem possible to get a key value pair like that, instead, it only seems possible to specifically set the Key for each value in the script like so: <code>[{Value_X: X, Value_Y: Y}, {Value_X: X2, Value_Y: Y2}, ...]</code></p>

<p>Here is my current DataWeave script that works, but gives me the second result:</p>

<pre><code>%dw 1.0
%output application/java
---

payload map {
    Value_X: $.X,
    Value_Y: $.Y
}
</code></pre>

<p>And here's the DataWeave script that I wish worked, but doesn't</p>

<pre><code>%dw 1.0
%output application/java
---

payload map {
    $.X: $.Y
}
</code></pre>