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 = JsonConvert.DeserializeXmlNode(json);

Documentation here: Converting between JSON and XML with Json.NET

Answer from David Brown on Stack Overflow
Top answer
1 of 12
499

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 = JsonConvert.DeserializeXmlNode(json);

Documentation here: Converting between JSON and XML with Json.NET

2 of 12
60

Yes, you can do it (I do) but Be aware of some paradoxes when converting, and handle appropriately. You cannot automatically conform to all interface possibilities, and there is limited built-in support in controlling the conversion- many JSON structures and values cannot automatically be converted both ways. Keep in mind I am using the default settings with Newtonsoft JSON library and MS XML library, so your mileage may vary:

XML -> JSON

  1. All data becomes string data (for example you will always get "false" not false or "0" not 0) Obviously JavaScript treats these differently in certain cases.
  2. Children elements can become nested-object {} OR nested-array [ {} {} ...] depending if there is only one or more than one XML child-element. You would consume these two differently in JavaScript, etc. Different examples of XML conforming to the same schema can produce actually different JSON structures this way. You can add the attribute json:Array='true' to your element to workaround this in some (but not necessarily all) cases.
  3. Your XML must be fairly well-formed, I have noticed it doesn't need to perfectly conform to W3C standard, but 1. you must have a root element and 2. you cannot start element names with numbers are two of the enforced XML standards I have found when using Newtonsoft and MS libraries.
  4. In older versions, Blank elements do not convert to JSON. They are ignored. A blank element does not become "element":null

A new update changes how null can be handled (Thanks to Jon Story for pointing it out): https://www.newtonsoft.com/json/help/html/T_Newtonsoft_Json_NullValueHandling.htm

JSON -> XML

  1. You need a top level object that will convert to a root XML element or the parser will fail.
  2. Your object names cannot start with a number, as they cannot be converted to elements (XML is technically even more strict than this) but I can 'get away' with breaking some of the other element naming rules.

Please feel free to mention any other issues you have noticed, I have developed my own custom routines for preparing and cleaning the strings as I convert back and forth. Your situation may or may not call for prep/cleanup. As StaxMan mentions, your situation may actually require that you convert between objects...this could entail appropriate interfaces and a bunch of case statements/etc to handle the caveats I mention above.

๐ŸŒ
Code Beautify
codebeautify.org โ€บ jsontoxml
Best JSON to XML Converter to convert JSON to XML String, File, URL
Best Online JSON to XML Converter, Transformer Online Utility. Load form URL, Download, Save and Share.
๐ŸŒ
JSON Formatter
jsonformatter.org โ€บ json-to-xml
Best JSON to XML Converter
JSON to XML helps convert JSON data to XML. It's very simple and easy way to transform and share JSON to XML data ... JSON Example with all data types including JSON Array. ... Best and Secure JSON to XML works well in Windows, Mac, Linux, Chrome, ...
๐ŸŒ
Convertjson
convertjson.com โ€บ json-to-xml.htm
JSON To XML Converter
Use this tool to convert JSON into XML format. New- Now supports JSONLines. Enter your JSON or JSONLines data below and Press the Convert button. The output will display below the Convert button.
๐ŸŒ
FreeFormatter
freeformatter.com โ€บ json-to-xml-converter.html
Free Online JSON to XML Converter - FreeFormatter.com
This free online tool lets you convert a JSON into an XML file and formats the output with your chosen indentation
๐ŸŒ
JSON Formatter
jsonformatter.org โ€บ xml-to-json
Best XML to JSON Converter Online
XML to JSON is very unique tool for convert JOSN to XML and allows to download, save, share and print XML to JSON data.. XML to JSON support URL linking for sharing json. i.e. https://jsonformatter.org/xml-to-json/?url=https://gist.githubusercontent.com/jimmibond/8b75d0afcf249601174f1f504664072a/raw/c28e51ac26861d39f900d88e3c9fe2490374dbd9/xmlsample
๐ŸŒ
GitHub
github.com โ€บ katie-snow โ€บ xml2json-c
GitHub - katie-snow/xml2json-c: A C library to pull in an XML file and have a json-c object available.
A C library to pull in an XML file and have a json-c object available. - katie-snow/xml2json-c
Author ย  katie-snow
๐ŸŒ
Site24x7
site24x7.com โ€บ tools โ€บ json-to-xml.html
Json to XML Converter: Site24x7 Tools
Site24x7s JSON to XML converter converts your JSON data to its equivalent XML format. The JSON keys are converted to XML elements and JSON values are transformed into element values. The tool supports attributes in XML Element.
Find elsewhere
๐ŸŒ
Newtonsoft
newtonsoft.com โ€บ json โ€บ help โ€บ html โ€บ ConvertJsonToXml.htm
Convert JSON to XML
This sample converts JSON to XML. Sample ยท Usage ยท Copy ยท string json = @"{ '@Id': 1, 'Email': 'james@example.com', 'Active': true, 'CreatedDate': '2013-01-20T00:00:00Z', 'Roles': [ 'User', 'Admin' ], 'Team': { '@Id': 2, 'Name': 'Software Developers', 'Description': 'Creators of fine software products and services.'
๐ŸŒ
Teleport
goteleport.com โ€บ resources โ€บ tools โ€บ json-to-xml-converter
JSON to XML Converter | Instant JSON to XML Conversion | Teleport
This makes understanding how to convert data between formats like JSON and XML important. Whether you're working with legacy applications or integrating differing systems, this primer will equip you with the knowledge to handle JSON to XML conversion effectively. In this article, weโ€™ll break down the characteristics ...
๐ŸŒ
C# Corner
c-sharpcorner.com โ€บ blogs โ€บ how-to-convert-json-into-xml-or-xml-into-json
How To Convert JSON Into XML Or XML Into JSON
July 21, 2016 - Another method to install is: Click Tools=> NuGet Package Manager=> Package Manager Console. Type โ€œPM> Install-Package Newtonsoft.Jsonโ€. DeserializeXmlNode() is the helper method to convert JSON to XML. See the example, given below: SerializeXmlNode() is another helper method used for converting XML to JSON.
๐ŸŒ
ReqBin
reqbin.com โ€บ json-to-xml
Online JSON to XML Converter
JSON to XML conversion is done right in the browser without sending requests to the server. The JSON to XML converter is simple and easy to use, with minimal configuration options. Enter JSON data and click "Convert JSON to XML" to convert JSON strings to XML data online and see the result.
๐ŸŒ
Oxygen XML
oxygenxml.com โ€บ doc โ€บ ug-editor โ€บ topics โ€บ convert-JSON-to-XML-x-tools.html
JSON to XML Converter
Select the Open in Editor option to open the resulting XML document in the main editing pane. Click the Convert button. Result: The original JSON document is now converted to an XML document.
๐ŸŒ
GitHub
github.com โ€บ testillano โ€บ json2xml
GitHub - testillano/json2xml: C++ Converter from Json to XML (based in nlohmann::json sax consumer) ยท GitHub
C++ header-only converter from Json to XML, based in also header-only nlohmann json library.
Starred by 17 users
Forked by 3 users
Languages ย  C++ 48.9% | CMake 25.2% | Python 21.2% | Perl 2.4% | Dockerfile 2.3%
๐ŸŒ
Utilities and Tools
utilities-online.info โ€บ xmltojson
XML to JSON & JSON to XML converter online
You can also convert your JSON code to XML by using our JSON to XML converter.
๐ŸŒ
FreeFormatter
freeformatter.com โ€บ xml-to-json-converter.html
Free Online XML to JSON Converter - FreeFormatter.com
This free online tool lets you convert an XML file into a JSON file with your choice of indentation
๐ŸŒ
Aspose
products.aspose.com โ€บ aspose.cells โ€บ c++ โ€บ conversion โ€บ json to xml
C++ JSON to XML - JSON to XML Converter | products.aspose.com
November 13, 2025 - Add a library reference (import the library) to your C++ project. Load JSON file using Workbook. Convert JSON to XML by calling Save() method.
๐ŸŒ
Code Beautify
codebeautify.org โ€บ xmltojson
XML to JSON Converter Online to convert XML to JSON String, URL and File
Best XML to JSON Converter, Transform Online Utility to convert XML to JSON. Paste or Load form URL or File, Download, Save and Share