Getting started Community Training Tutorials Documentation APIs, AI & Tools
%dw 2.0
output application/json
---
{ "keysOf" : keysOf({ "a" : true, "b" : 1}) }
Returns an array of keys from key-value pairs within the input object.
The returned keys belong to the Key type. To return each key as a string, you can use namesOf, instead.
Introduced in DataWeave version 2.3.0.
This example illustrates a difference between keysOf and namesOf.
Notice that keysOf retains the attributes (name and lastName)
and namespaces (xmlns) from the XML input, while namesOf returns
null for them because it does not retain them.
%dw 2.0
var myVar = read('<users xmlns="http://test.com">
<user name="Mariano" lastName="Achaval"/>
<user name="Stacey" lastName="Duke"/>
</users>', 'application/xml')
output application/json
---
{ keysOfExample: flatten([keysOf(myVar.users) map $.#,
keysOf(myVar.users) map $.@])
}
++
{ namesOfExample: flatten([namesOf(myVar.users) map $.#,
namesOf(myVar.users) map $.@])
}