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
๐ŸŒ
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
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.

๐ŸŒ
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
๐ŸŒ
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
๐ŸŒ
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
๐ŸŒ
ReqBin
reqbin.com โ€บ xml-to-json
Online XML to JSON Converter
JSON is a format that originated from JavaScript but is now used by almost all programming languages, including PHP, Python, Java, C++, C#, and Go. JSON files have the *.json extension. ... Copy and paste the XML code into the left input box. Click ...
Find elsewhere
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ utilities โ€บ xml-to-json-converter
XML to JSON Converter - Free Online Tools %%page%% %%sep%% %%sitename%% - GeeksforGeeks
October 4, 2024 - The XML to JSON Converter tool facilitates seamless conversion of XML data structures into JSON format, aiding interoperability and compatibility between different data formats for enhanced data manipulation and integration capabilities.
๐ŸŒ
GitHub
github.com โ€บ Cheedoong โ€บ xml2json
GitHub - Cheedoong/xml2json: A header-only C++ library converts XML to JSON ยท GitHub
xml2json is the first carefully written C++ library that converts XML document to JSON format.
Starred by 315 users
Forked by 103 users
Languages ย  C++ 84.3% | HTML 13.0% | C 2.5% | Makefile 0.2%
๐ŸŒ
CodeShack
codeshack.io โ€บ home โ€บ tools โ€บ xml to json converter
XML to JSON Converter
Convert XML into JSON format online, save the output to a file or copy and paste into your projects. Free to use online tool, quickly convert any XML file or text.
๐ŸŒ
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.
๐ŸŒ
Altova
altova.com โ€บ xmlspy-xml-editor โ€บ xml-to-json
XML to JSON Converter | Altova
In addition to powerful conversion utilities, XMLSpy includes a JSON and XML editors, as well as support for working with XPath, XSLT, and XQuery alongside both technologies. You can convert a single file or perform a mass conversion on a large number of XML files instantly.
๐ŸŒ
Site24x7
site24x7.com โ€บ tools โ€บ xml-to-json.html
XML to JSON Converter: Site24x7 Tools
Free tool which converts your XML data to its equivalent JSON format.The XML elements are converted to JSON keys and element values are transformed to corresponding JSON values.
๐ŸŒ
Convertjson
convertjson.com โ€บ xml-to-json.htm
XML To JSON Converter
The tool will convert a XML file to JSON format.
๐ŸŒ
Utilities and Tools
utilities-online.info โ€บ xmltojson
XML to JSON & JSON to XML converter online
XML to JSON converter enables you to convert XML file to JSON file. It converts the XML elements into the JSON keys within a fraction of seconds. ... Write or paste XML code in the left input box. Click the Right Arrow button.
๐ŸŒ
Teleport
goteleport.com โ€บ resources โ€บ tools โ€บ xml-to-json-converter
XML to JSON Converter | Instant XML to JSON Conversion | Teleport
This native compatibility simplifies data handling in web applications, allowing for the seamless transfer of data between server and client. XML to JSON conversion involves transforming the hierarchical structure of XML into the flatter, key-value pair format of JSON. Let's break down this process: Mapping XML Elements and Attributes: Each XML element is mapped to a corresponding JSON object. Attributes in XML are typically converted into key-value pairs within the corresponding JSON object.
๐ŸŒ
Integrate.io
integrate.io โ€บ home โ€บ blog โ€บ conversions โ€บ how to convert xml to json: a step-by-step guide
How to Convert XML to JSON: A Step-by-Step Guide | Integrate.io
July 21, 2025 - This conversion is critical to ensure data interoperability, enhance system compatibility, and optimize data handling and storage. In this post, we guide you through the step-by-step process of converting XML to JSON.
๐ŸŒ
Aspose
products.aspose.com โ€บ aspose.cells โ€บ .net โ€บ conversion โ€บ xml to json
C# XML to JSON - XML to JSON Converter | products.aspose.com
November 13, 2025 - Add a library reference (import the library) to your C# project. Load XML file with an instance of Workbook. Convert XML to JSON by calling Workbook.Save method.