XML to Json
XML to Json
Source
//// 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();
doc.LoadXml(xml);
return JsonConvert.SerializeXmlNode(doc);
}
Example
String xmlString = "C:my.xml";
var jsonResult = xmlString.ToJSON();