How To Convert JSON Into XML Or XML Into JSON

Introduction

In this blog, we will learn how to convert JSON to XML and XML to JSON

JSON.NET

Json.NET is a popular high-performance JSON framework for .NET. We can do more with this as JSON.NET supports converting JSON to XML and vice versa, LINQ to JSON, Serializing and Deserialize JSON.

References

  • http://www.newtonsoft.com/json/help/html/Introduction.htm
  • https://json.codeplex.com/
How to install JSON.NET in Visual Studio

Click on the “References” => Manage NuGet Packages

References
Click the Install Button.

Install

Click OK. Now, the installation completes.

installation

Another method to install is:

Click Tools=> NuGet Package Manager=> Package Manager Console.

NuGet Package Manager

Type “PM> Install-Package Newtonsoft.Json”.

Install

DeserializeXmlNode() is the helper method to convert JSON to XML.

See the example, given below:

code

SerializeXmlNode() is another helper method used for converting XML to JSON.

See the example, given below:

code

Conclusion

In this blog, we learned to convert JSON to XML and XML to JSON with simple code.
Next Recommended Reading XML Creation using LINQ to XML