DataWeave : mapObject()

DataWeave : mapObject()

mapObject() :

It transforms an Object to a new Object. mapObject is used when we want to change the keys and/or values on an Object to be a different object.

It does this by iterating over each key/value pair in the object and applying a transformation to each key and value. The result of the transformation is collected together and output as an object.

Note : An Object starts with { and end with } and inside it has key-value pairs or nil
Note : Whenever we are applying mapObject function other than the Objects, we get the exception

mapObject(Object, (Value,Key,index) -> Object): Object

Value(default $): it represents the value part of a key-value pair in an object

Example :
ex1.PNG

In the above image James Peter belongs to Value(default $) part

Example : ex2.PNG


Key(default $$) : it represents the key part of a key-value pair in an object Example : ex3.PNG

In the above image name belongs to Key(default $$) part

ex4.PNG


index(default $$$) : it represents the position part of a key-value pair in an object

Example :

ex5.PNG

Example :

ex6.PNG


Exception case:

Here we got an error while applying mapObject on an Array

ex7.PNG

Thank you for taking out time to read the above post. Hope you found it useful. In case of any questions, feel free to comment below. Also, if you are keen on knowing about a specific topic, happy to explore your recommendations as well.

#mulesoft #dataweave #dw #anypointstudio #mule #muleEsb #mapObject#mapObject()