Converting between JSON and XML using Json.NET

SerializeXmlNode


The JsonConvert has two helper methods for converting between JSON and XML. The first is SerializeXmlNode. This method takes an XmlNode and serializes it to JSON text.
string xml = @"<?xml version=""1.0"" standalone=""no""?>
<root>
  <person id=""1"">
  <name>Alan</name>
  <url>http://www.google.com</url>
  </person>
  <person id=""2"">
  <name>Louis</name>
  <url>http://www.yahoo.com</url>
  </person>
</root>";
 
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
//for deserialize it in to json
string jsonText = JsonConvert.SerializeXmlNode(doc);
Next Recommended Reading What is Json.NET