# DataWeave : filterObject()

## filterObject ()  : 

filterObject  always works on Objects. It Iterates over key-value pairs in an object and applies a conditional expression that returns only matching key value pairs, filtering out the unmatched key value pairs.

The conditional  expression must return true or false. 
If the expression returns true for a key, value, or index of an object, the object gets in the output. 

If it returns false for any of them, the object gets filtered out of the output. If there are no matches, the output array will be empty.


```
Note : An Object starts with { and end with } and inside it has key-value pairs or nil
```

```
Note : Whenever we are applying filterObject function other than the Objects and null, we get the exception
``` 


**filterObject (Object<Key,Value>, (Value,Key,index) -> Object): Object **

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

** Example : ** 

In the below image we are applying filterObject 

**condition:  ** filtering key-value pairs with values starts with "N" character

![fo1.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1647241331717/ksMDQ04XE.PNG)

with default syntax  :


![f04.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1647323054122/5aBJtebKO.PNG)

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

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

** Example : ** 


![fo2.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1647241389022/M6c2fUNF1.PNG)

with default syntax :


![f03.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1647322979989/z_Ny3fYM0.PNG)

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

** Example : ** 


![f06.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1647323397609/vqEBtmikQ.PNG)

with default  syntax :


![f05.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1647323422807/rcXwhqLPd.PNG)

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

**When input is null:**

filterObject gives null as output when input is null

**Example:**

![f07.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1647323662394/bw73KY_Mf.PNG)
-----------------------------------------------------------------------------------------

** Exception case: **

Here we got an error while applying filterObject on an Array


![f08.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1647323812737/VoXrecfzZ.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 #filterObject #filterObject ()





