Skip to content
+1-888-319-3663

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


2021 Q4 Promotions
Connect with us at Directions EMEA 2021 in Milan!
eOne at Summit North America 2021
Employee Spotlight: Megan Tripp, Business Development Representative
eOne is now compatible with Microsoft Dynamics GP October 2021 Release

POPULAR POSTS


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

CATEGORIES

TAGS

Business Central CRM D365 Business Central Dynamics 365 dynamics crm Dynamics GP Dynamics NAV Econnect Employee Spotlight eone eOne News error Error Message Events Excel Excel Report Builder Extender Flexicoder GP integration Map Meet the Team Microsoft dynamics crm Microsoft Dynamics GP Navigation List Builder Office Relationships partners Popdock release Reporting SalesForce SalesForce.com SmartConnect SmartConnect.com SmartConnect Bootcamp SmartConnect Maps SmartConnect Office Hours SmartList SmartList Builder SmartPost SmartView SQL Tech Tuesday Templates training

Integrate & Automate without Any Code.

SmartList Data has Never Been Faster.

The Easiest Way to Report on GP Data.