I am a beginner in using dataweave transformation, I am trying to write a Mule 4 dataweave expression to convert input JSON into output XML format, I have a payload in JSON format and I want to convert it into a specific XML format, below is the actual JSON along with output XML
product-id(XML) tag will come from = name attribute of PBSI__Item__r tag of JSON and allocation value in XML comes from name attribute of PBSI__Inventory__r tag
JSON:
[
{
"PBSI__Item__r": {
"Id": null,
"type": "PBSI__PBSI_Item__c",
"Name": "116065"
},
"PBSI__Inventory__r": [
{
"Id": null,
"type": "PBSI__PBSI_Inventory__c",
"PBSI__Real_Quantity__c": "13.0"
}
],
"PBSI__Location__r": {
"Id": null,
"type": "PBSI__PBSI_Location__c",
"Name": "OB043"
},
"Id": null,
"type": "PBSI__Lot__c"
},
{
"PBSI__Item__r": {
"Id": null,
"type": "PBSI__PBSI_Item__c",
"Name": "116066"
},
"PBSI__Inventory__r": [
{
"Id": null,
"type": "PBSI__PBSI_Inventory__c",
"PBSI__Real_Quantity__c": "1.0"
}
],
"PBSI__Location__r": {
"Id": null,
"type": "PBSI__PBSI_Location__c",
"Name": "OA011"
},
"Id": null,
"type": "PBSI__Lot__c"
}
]
output XML:
<?xml version='1.0' encoding='UTF-8'?>
<inventory xmlns="http://www.demandware.com/xml/impex/inventory/2007-05-31">
<inventory-list>
<header list-id="Hastens_Inventory">
<default-instock>false</default-instock>
<use-bundle-inventory-only>false</use-bundle-inventory-only>
</header>
<records>
<record product-id="116065">
<allocation>13</allocation>
<allocation-timestamp>2019-04-24T07:09:51.954Z</allocation-timestamp>
</record>
<record product-id="116066">
<allocation>1</allocation>
<allocation-timestamp>2019-04-24T07:09:51.965Z</allocation-timestamp>
</record>
</records>
</inventory-list>
</inventory>