EONE BLOG

Using Newtonsoft with SmartConnect to Convert JSON to XML


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 Bin\net45 directory. Paste the file into C:\Program Files (x86)\eOne Solutions\SmartConnect and C:\Windows\Microsoft.NET\Framework\v4.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_FILE\tech_tuesday.json"))
Dim node As XNode = JsonConvert.DeserializeXNode(o1.ToString, "Root")
File.WriteAllText("C:\PATH_TO_SAVE\json_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.

The sample json and xml files can be downloaded here.

Leave a Comment




RECENT POSTS


Tech Tuesday: Connecting to Sales 365 with Multi Factor Authentication
SmartConnect Office Hours Recap for April 19th, 2019
What is a Popdock Widget?
Tech Tuesday: Conditionally Auto Opening an Extender Window with Extender Enterprise
Sign Up Ends Soon! SmartConnect Bootcamp for GP or BC/NAV in Las Vegas

POPULAR POSTS


2016 SmartConnect Integration Bootcamps
Tech Tues: Automatically refreshing Pivot Tables in Excel Refreshable Reports
Happy Thanksgiving from the eOne team!
New Releases of Extender and SmartList Builder
2017 SmartConnect Integration Bootcamps

CATEGORIES

ARCHIVES

open all | close all

TAGS

CRM Demo Dynamics 365 dynamics crm Dynamics GP Dynamics NAV Econnect Employee Spotlight eone eOne News eOne Spotlight ERP Events Excel Excel Report Builder Extender Extender Enterprise Flexicoder GP GPUG integration integration manager Meet the Team Microsoft dynamics crm Microsoft Dynamics GP Office Relationships partners Popdock release SalesForce SalesForce.com scripting SmartConnect SmartConnect.com SmartConnect Office Hours SmartList SmartList Builder SmartList Designer SmartView SQL Support Tech Tuesday Templates training Zendesk

Integrate & Automate without Any Code.

SmartList Data has Never Been Faster.

The Easiest Way to Report on GP Data.