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

JSON to XML

json to xml

Source

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

public static string ToXML(this string json)
{
      // To convert JSON text contained in string json into an XML node
      XmlDocument doc = JsonConvert.DeserializeXmlNode(json);
      return doc.ToString();
}

Example

{"menu": {
  "id": "file",
  "value": "File",
  "popup": {
    "menuitem": [
      {"value": "New", "onclick": "CreateNewDoc()"},
      {"value": "Open", "onclick": "OpenDoc()"},
      {"value": "Close", "onclick": "CloseDoc()"}
    ]
  }
}}

Author: Keyur Panchal

Submitted on: 11 aug. 2015

Language: C#

Type: Json, XML, C#

Views: 6634