ExtensionMethod.NET Home of 829 C#, Visual Basic, F# and Javascript extension methods

XML to Json

XML to Json


//// Install nuget package for Newtonsoft json
//// https://www.nuget.org/packages/Newtonsoft.Json/
//// Install-Package Newtonsoft.Json

 public static string ToJSON(this string xml)
    // To convert an XML node contained in string xml into a JSON string
    XmlDocument doc = new XmlDocument();
    return JsonConvert.SerializeXmlNode(doc);


String xmlString = "C:my.xml";
var jsonResult = xmlString.ToJSON();

Author: Keyur Panchal

Submitted on: 11 aug 2015

Language: C#

Type: XML, JSON, C#

Views: 4384