Home > DeveloperSection > Forums > Json.NET: convert JSON string to XML or XML to JSON string
Jayden Bell
Jayden Bell

Total Post:110

Posted on    May-29-2013 1:42 AM


 1 Reply(s)
 2044  View(s)
Rate this:
Hi Everyone,

I started to use Json.NET to convert a string in JSON format to object or vice-versa. I am not sure in the JSON.NET framework, is it possible to convert a string in 

JSON to XML format and vice-versa?

Thanks in advance. 


Total Post:604

Posted on    May-29-2013 9:01 AM

Hi Jayden!

Yes. Using the JsonConvert class which contains helper methods for this precise purpose:

// To convert an XML node contained in string xml into a JSON string   
XmlDocument doc = new XmlDocument();
string jsonText = JsonConvert.SerializeXmlNode(doc);

// To convert JSON text contained in string json into an XML node
XmlDocument doc = (XmlDocument)JsonConvert.DeserializeXmlNode(json);

Don't want to miss updates? Please click the below button!

Follow MindStick