Hear from Salesforce leaders on how to create and deploy Agentforce agents.
Contact Us 1-800-596-4880

Map Objects

This DataWeave example uses both the map and mapObject functions to iterate through the input and set all of the keys to upper case. Before you begin, note that DataWeave version 2 (%dw 2.0) is for Mule 4 apps. For a Mule 3 app, refer to DataWeave version 1 (%dw 1.0) examples, within the Mule 3.9 documentation set. For other Mule versions, you can use the Mule Runtime version selector in the table of contents.

The example uses these DataWeave functions:

  • map to go through the elements in the "books" array.

  • mapObject to go through the keys and values in each of the objects of the array.

  • upper to set each key to upper case.

DataWeave Script:
%dw 2.0
output application/json
---
items: payload.books map (item, index) -> {
      book: item mapObject (value, key) -> {
      (upper(key)): value
      }
}
dataweave
Input JSON Payload:
Output JSON: