Convert JSON to XML

When you need input data from JSON files, you first need to convert JSON files to XML files to make the data compatible with AIMMS.

Here we provide a conversion tool in the form of a custom AIMMS library. It contains a conversion AIMMS library between XML and JSON files:

  • ConvertFromJsonToXML

  • ConvertFromXMLToJson


  1. Download

  2. Extract the two folders and put them at the root of your project.

  3. Then add this library to your project:

    1. Open the Library Manager.

    1. Click Add existing library.

    1. Select the JSONXML folder and click Select a folder

    1. Click OK to exit the library manager.

  1. Then by calling the method jxml::ConvertFromJsonToXML you should be able to obtain your data into an XML file.

Execute the following code to create the XML file:


During the conversion, the general structure of the JSON file is conserved. For every JSON element, an XML element is created.

Note that if the JSON element had a name, then it will be set as a parameter of the corresponding XML element.


Extracting data.

Extracting data from this XML requires a quite specific process. You can see in the image above that each element has an element name in the format json:Object-Type. When you’ll generate your XSD file, this notation will not be there anymore and you’ll only have Object-Type.

Hence, by generating the .AXM file using the XML schema mapping tool with that XSD, the AXM will neither have this notation. So, the XMLREAD() method will not be executed properly because AXM and XML will have different element names.

In order to solve this situation, you can follow this process:

  • Generate your XSD file as usual.

  • Create your mapping using the XML schema mapping tool

  • Edit your AXM file at the root of your project by transforming every element name ElementMapping name=”(OBJECT-TYPE)” into ElementMapping name=”json:(OBJECT-TYPE)”


be careful to transform only element names and not attributes names.

If you want more details about the general steps to extract data from an XML file you can check this article : Extract Data from an XML File.