Converting JSON files to XML
This tutorial will help you to convert JSON files to XML format using the JSON to XML task in Zynk.
The JSON to XML Task
The JSON connector in Zynk contains tasks that allow you to convert JSON files to and from XML. This is useful when integrating with JSON files, as the majority of the tasks in Zynk expect their input and output files to be in XML format.
JSON to XML
In this example, we will use the following example JSON file:
{
"Products": {
"Product": {
"UniqueId": "PRODUCT",
"Sku": "PRODUCT",
"Barcode": "5019301023118",
"Name": "Test Product",
"Description": "Test Product for Sage 50",
"SalePrice": "396",
"UnitWeight": "0",
"QtyInStock": "0",
"QtyOnOrder": "0",
"ReorderQty": "0",
"ReorderLvl": "0",
"TaxCode": "1",
"GroupCode": "14",
"GroupName": "Other",
"Department": "6",
"UnitOfSale": "EA",
"NominalCode": "4000",
"Publish": "false",
"ProductLevel": "0",
"SpecialOffer": "false",
"QtyAllocated": "0",
"ImageName": "(none)",
"LastCostPrice": "316.8",
"LastCostPriceDiscounted": "316.8",
"QtyLastOrder": "7",
"AverageCostPrice": "316.8",
"SupplierDepartment": "6",
"PurchaseNominalCode": "5006",
"UseDescriptionOnDocs": "false",
"ItemType": "Service",
"IsActive": "true"
}
}
}
The task settings are configured as follows:
- Root Element Name - This is set to "Company". This setting is required to make the above file match out Zynk XML format. If the JSON file already contains a root or is being transform after conversion, this setting can be left blank which will cause the task to use the root from the JSON file.
- Input File - This is the JSON file we want to convert to XML.
- Output File - This is the file the resulting XML will be saved to.
This creates the following output:
<?xml version="1.0" encoding="utf-8"?>
<Company>
<Products>
<Product>
<UniqueId>PRODUCT</UniqueId>
<Sku>PRODUCT</Sku>
<Barcode>5019301023118</Barcode>
<Name>Test Product</Name>
<Description>Test Product for Sage 50</Description>
<SalePrice>396</SalePrice>
<UnitWeight>0</UnitWeight>
<QtyInStock>0</QtyInStock>
<QtyOnOrder>0</QtyOnOrder>
<ReorderQty>0</ReorderQty>
<ReorderLvl>0</ReorderLvl>
<TaxCode>1</TaxCode>
<GroupCode>14</GroupCode>
<GroupName>Other</GroupName>
<Department>6</Department>
<UnitOfSale>EA</UnitOfSale>
<NominalCode>4000</NominalCode>
<Publish>false</Publish>
<ProductLevel>0</ProductLevel>
<SpecialOffer>false</SpecialOffer>
<QtyAllocated>0</QtyAllocated>
<ImageName>(none)</ImageName>
<LastCostPrice>316.8</LastCostPrice>
<LastCostPriceDiscounted>316.8</LastCostPriceDiscounted>
<QtyLastOrder>7</QtyLastOrder>
<AverageCostPrice>316.8</AverageCostPrice>
<SupplierDepartment>6</SupplierDepartment>
<PurchaseNominalCode>5006</PurchaseNominalCode>
<UseDescriptionOnDocs>false</UseDescriptionOnDocs>
<ItemType>Service</ItemType>
<IsActive>true</IsActive>
</Product>
</Products>
</Company>