Converting XML files to JSON
This tutorial will help you to convert XML files to JSON format using the XML to JSON task in Zynk.
The XML to JSON Task
Most of the tasks within Zynk are set up to use standard XML as the input and output. In some cases, outside systems may require data in other formats (such as JSON). This tutorial demonstrates how to use this task by taking an example XML file and converting it to JSON
XML to JSON
In this example, we will use the following example XML file:
<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>
This task takes the example XML file above and converts it into JSON. The task settings are configured as follows:
- Omit Root Object - If set to "True" this will omit the first root object, which in this case is "Company"
- Input File - This is the XML file we want to convert to JSON.
- Output File - This is the file the resulting JSON will be saved to.
This creates the following output:
{
"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"
}
}
}