How to convert JSON to XML or XML to JSON in C# ?

Below is a sample code snippet demonstrating how you can convert the Json to XML and vice versa in C# using Json.NET.

How to convert JSON to XML or XML to JSON in C# ?

var xmlData = "<xmlcontent></xmlcontent>" 
XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlData);
string jsonText = JsonConvert.SerializeXmlNode(doc);

// Convert Json back to XML
XmlDocument xmlDoc = JsonConvert.DeserializeXmlNode(json);