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

Total Post:105

Points:739
Posted on    May-29-2013 1:42 AM

 JSON JSON 
Ratings:


 1 Reply(s)
 1656  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. 


AVADHESH PATEL

Total Post:604

Points:4228
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();
doc.LoadXml(xml);
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