Contact Free trial Login

mapObject

mapObject({ (K)?: V }, (value: V, key: K, index: Number) -> Object): Object

Transforms each key-value pair of an object using the specified mapper function.

Parameters

Name Description

object

The object to transform.

mapper

Function that receives the key, value and index (optional) and returns the transformed key-value pair.

Example

This example increases each price by 5 and formats the numbers to always include 2 decimals.

Source

%dw 2.0
output application/xml
---
{
    prices: payload.prices mapObject (value, key) -> {
        (key): (value + 5) as Number {format: "##.00"}
    }
}

Input

<?xml version='1.0' encoding='UTF-8'?>
<prices>
    <basic>9.99</basic>
    <premium>53</premium>
    <vip>398.99</vip>
</prices>

Output

<?xml version='1.0' encoding='UTF-8'?>
<prices>
  <basic>14.99</basic>
  <premium>58.00</premium>
  <vip>403.99</vip>
</prices>

mapObject(Null, (value: Nothing, key: Nothing, index: Number) -> Nothing): Null

Helper function that allows mapObject to work with null values.

We use cookies to make interactions with our websites and services easy and meaningful, to better understand how they are used and to tailor advertising. You can read more and make your cookie choices here. By continuing to use this site you are giving us your consent to do this.