# 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<Key,Value>, (Value,Key,index) -> Object): Object **

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

** Example : **  
![ex1.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1646635040102/kMzpBDEO6.PNG)

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

** Example : ** 
![ex2.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1646635675350/Eghlhpb0W.PNG)

-----------------------------------------------------------------------------------------

** Key(default $$) :** it represents the key part of a key-value pair  in an object
** Example : ** 
![ex3.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1646635956688/n0CE0pM3L.PNG)

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

![ex4.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1646637062596/JkPTvpd_ci.PNG)

-----------------------------------------------------------------------------------------


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

** Example : **

![ex5.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1646637079543/3ejpTgscr.PNG)

** Example : **



![ex6.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1646638256495/hM-caEak7.PNG)

-----------------------------------------------------------------------------------------

** Exception case: **

Here we got an error while applying mapObject on an Array


![ex7.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1646638400792/ngNbFTMib.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()



