title: Return elements of a JSON object as an array
body: <p>I have an XML file that is converted to a JSON object by a TRANSFORM MESSAGE:</p>
  <pre><code>%dw 2.0
  output application/json
  ---
  payload
  </code></pre>
  <p>The resulting JSON object has a format of:</p>
  <pre><code>{
    &quot;Items&quot;: {
      &quot;Item&quot;: {
        &quot;ItemId&quot;: &quot;123&quot;,
        &quot;OrganizationId&quot;: &quot;456&quot;,
        &quot;OrganizationCode&quot;: &quot;ABC&quot;,
  </code></pre>
  <p>where there is one &quot;Items&quot; and 112 &quot;Item&quot;. What I want is to return an JSON array contains all of the ItemIds. I am attempting to use TRANSFORM MESSAGE within a FOREACH. The FOREACH has 'payload' in the collection field and TRANSFORM MESSAGE has:</p>
  <pre><code>%dw 2.0
  output application/json
  ---
  myItems: payload.items.*item map (item, index) -&gt; {
      &quot;myItemId&quot; : item.ItemId
  }
  </code></pre>
  <p>However, it always returns everything, the entire JSON object. I can't figure out if my FOREACH is wrong or if my TRANSFORM MESSAGE is wrong, but it always returns the entire JSON object.</p>
  <hr />
  <p>An example of the incoming JSON would be:</p>
  <pre><code>{
    &quot;Items&quot;: {
      &quot;Item&quot;: {
        &quot;ItemId&quot;: &quot;8041&quot;,
        &quot;OrganizationId&quot;: &quot;12&quot;,
        &quot;OrganizationCode&quot;: &quot;ABC&quot;,
      },
      &quot;Item&quot;: {
        &quot;ItemId&quot;: &quot;8050&quot;,
        &quot;OrganizationId&quot;: &quot;12&quot;,
        &quot;OrganizationCode&quot;: &quot;ABC&quot;,
      },
      &quot;Item&quot;: {
        &quot;ItemId&quot;: &quot;3801&quot;,
        &quot;OrganizationId&quot;: &quot;12&quot;,
        &quot;OrganizationCode&quot;: &quot;ABC&quot;,
      }
    }
  }
  </code></pre>
  <p>The output should be: [&quot;8041&quot;, &quot;8050&quot;, &quot;3801&quot;]. Parse the Item elements, extract the ItemID value and create a JSON array.</p>