In DataWeave, we have two properties which will hep us to optimize our application data.
- duplicateKeyAsArray: JSON data does not allow duplicate keys within same parent, so we may get exception in real-time project development scenario. With this attribute, if your dataweave finds any duplicate keys, it will create an array with all those values.
Sample XML Input:
<users>
<user>
<personal_information>
<first_name version=”V1″>Manish</first_name>
<first_name version=”V1″>Mak</first_name>
<middle_name>Kumar</middle_name>
<last_name>Sah</last_name>
</personal_information>
</user>
</users>
Dataweave Script:
%dw 2.0
output application/json duplicateKeyAsArray=true
—
payload
Sample Output:
{
“users”: {
“user”: {
“personal_information”: {
“first_name”: [
“Manish”,
“MaK”
],
“middle_name”: “Kumar”,
“last_name”: “Sah”
}
}
}
}
- indent: It indicates whether you want to compress your JSON data into a single line or you need JSON data for better readability.
<users>
<user>
<personal_information>
<first_name version=”V1″>Manish</first_name>
<first_name version=”V1″>Mak</first_name>
<middle_name>Kumar</middle_name>
<last_name>Sah</last_name>
</personal_information>
</user>
</users>
Dataweave Script:
%dw 2.0
output application/json duplicateKeyAsArray=true, indent=false
—
payload
Sample Output:
{“users”: {“user”: {“personal_information”: {“first_name”: [“Manish”,”MaK”],”middle_name”: “Kumar”,”last_name”: “Sah”}}}}
Happy Learning 🙂
Hiya, I’m really glad I’ve found this info. Today bloggers publish just about gossips and net and this is really annoying. A good blog with interesting content, this is what I need. Thanks for keeping this web-site, I will be visiting it. Do you do newsletters? Cant find it.
Subscription Enabled! you can subscribe now!!
Oh my goodness! an amazing article dude. Thank you However I am experiencing issue with ur rss . Don?t know why Unable to subscribe to it. Is there anyone getting identical rss problem? Anyone who knows kindly respond. Thnkx
Subscription Enabled. You can subscribe now!!