In this article we will add Newtonsoft to SmartConnect and use it to convert a json file to xml.
To start, you will need to load Newtonsoft into SmartConnect. Download the Newtonsoft.Json.dll
file from here (https://github.com/JamesNK/Newtonsoft.Json/releases). You will need to download the complete zip file found under Assets. At the time of this writing the most recent will be Json120r1.zip
. Once you have the zip file downloaded, copy the Newtonsoft.Json.dll
file from the Binnet45
directory. Paste the file into the following folders:
C:Program Files (x86)eOne SolutionsSmartConnect
C:WindowsSysWOW64
C:WindowsMicrosoft.NETFrameworkv4.0.30319
C:WindowsMicrosoft.NETFramework64v4.0.30319
Once the files have been copied to the necessary directories we can add the namespaces in SmartConnect. From the Newtonsoft.json assembly, add the Newtonsoft.Json and Newtonsoft.Json.Linq namespaces.
From the system.xml.linq assembly, add the System.Xml.Linq namespace.
From the system.core assembly add the System.Linq namespace.
After all namespaces have been added to the Current Namespaces section, click OK and restart SmartConnect.
As mentioned before, the goal is to use Newtonsoft in this example to convert a json file to xml, but you can use Newtonsoft for many things. Refer to the Newtonsoft documentation (https://www.newtonsoft.com/json/help/html/Introduction.htm) for more information.
I am going to use a pre-map task to convert my json file to xml and then use that generated xml as a data source on the same map. My pre-map task will be a Run Script task:
Dim o1 As JObject = JObject.Parse(File.ReadAllText("C:PATH_TO_YOUR_FILEtech_tuesday.json"))
Dim node As XNode = JsonConvert.DeserializeXNode(o1.ToString, "Root")
File.WriteAllText("C:PATH_TO_SAVEjson_to_xml.xml", node.ToString)
This will convert my tech_tuesday.json
file to xml and save an xml file called json_to_xml.xml
. To complete the map setup, this xml file will already have to exist to be selected as the data source. If you do not have an xml file with the correct formatting, you can setup a dummy source and destination so that you can run the map and have the pre-map task create the properly formatted xml file which you can then point to as the source when modifying the map. For me, this is a quicker process than creating my own xml that will match the converted json.