You may take a look at the Json-lib Java library, that provides XML-to-JSON conversion.

CopyString xml = "<hello><test>1.2</test><test2>123</test2></hello>";
XMLSerializer xmlSerializer = new XMLSerializer();  
JSON json = xmlSerializer.read( xml );  

If you need the root tag too, simply add an outer dummy tag:

CopyString xml = "<hello><test>1.2</test><test2>123</test2></hello>";
XMLSerializer xmlSerializer = new XMLSerializer();  
JSON json = xmlSerializer.read("<x>" + xml + "</x>");  
Answer from Tommy Siu on Stack Overflow
๐ŸŒ
JSON Formatter
jsonformatter.org โ€บ xml-to-json
Best XML to JSON Converter Online
Best and Secure XML to JSON works well in Windows, Mac, Linux, Chrome, Firefox, Safari and Edge. ... XML to JSON is very unique tool for convert JOSN to XML and allows to download, save, share and print XML to JSON data..
๐ŸŒ
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
๐ŸŒ
CodeShack
codeshack.io โ€บ home โ€บ tools โ€บ xml to json converter
XML to JSON Converter
Convert your XML text or file into JSON format. Fast, free, and simple, all you need to do is enter valid XML text into the first text box. Copy or download the JSON once the XML is converted.
Top answer
1 of 9
13

You may take a look at the Json-lib Java library, that provides XML-to-JSON conversion.

CopyString xml = "<hello><test>1.2</test><test2>123</test2></hello>";
XMLSerializer xmlSerializer = new XMLSerializer();  
JSON json = xmlSerializer.read( xml );  

If you need the root tag too, simply add an outer dummy tag:

CopyString xml = "<hello><test>1.2</test><test2>123</test2></hello>";
XMLSerializer xmlSerializer = new XMLSerializer();  
JSON json = xmlSerializer.read("<x>" + xml + "</x>");  
2 of 9
10

There is no direct mapping between XML and JSON; XML carries with it type information (each element has a name) as well as namespacing. Therefore, unless each JSON object has type information embedded, the conversion is going to be lossy.

But that doesn't necessarily matter. What does matter is that the consumer of the JSON knows the data contract. For example, given this XML:

Copy<books>
  <book author="Jimbo Jones" title="Bar Baz">
    <summary>Foo</summary>
  </book>
  <book title="Don't Care" author="Fake Person">
    <summary>Dummy Data</summary>
  </book>
</books>

You could convert it to this:

{
    "books": [
        { "author": "Jimbo Jones", "title": "Bar Baz", "summary": "Foo" },
        { "author": "Fake Person", "title": "Don't Care", "summary": "Dummy Data" },
    ]
}

And the consumer wouldn't need to know that each object in the books collection was a book object.

Edit:

If you have an XML Schema for the XML and are using .NET, you can generate classes from the schema using xsd.exe. Then, you could parse the source XML into objects of these classes, then use a DataContractJsonSerializer to serialize the classes as JSON.

If you don't have a schema, it will be hard getting around manually defining your JSON format yourself.

๐ŸŒ
Altova
altova.com โ€บ xmlspy-xml-editor โ€บ xml-to-json
XML to JSON Converter | Altova
One-click XML to JSON converter: try XMLSpy for free for 30 days. Learn about other options for JSON/XML conversion.
๐ŸŒ
Teleport
goteleport.com โ€บ resources โ€บ tools โ€บ xml-to-json-converter
XML to JSON Converter | Instant XML to JSON Conversion | Teleport
Convert XML data to JSON instantly with our free online tool. Simplify your data conversions with fast, accurate processing.
๐ŸŒ
SourceForge
sourceforge.net โ€บ projects โ€บ xml2json-converter
Xml2Json Converter download | SourceForge.net
Xml2Json Converter
Download Xml2Json Converter for free. Simple tool for converting large XML-files to JSON or JSON to XML. Simple converter tool with GUI (written on JavaFX) for converting large XML-files to JSON and JSON to XML with indicating progress and uses small amount of memory for converting. Simple converter tool with GUI (written on JavaFX) for converting large XML-files to JSON and JSON to XML with indicating progress and uses small amount of memory for converting. ยท Starting from 1.2.0 application supports batch converting files from directory by pattern. ยท Uses Java 1.8+ (http://www.oracle.com/tech
Rating: 4 โ€‹
๐ŸŒ
GitHub
github.com โ€บ sinelaw โ€บ xml-to-json
GitHub - sinelaw/xml-to-json: Fast & easy command line tool for converting XML files to JSON ยท GitHub
Fast & easy library & command line tool for converting XML files to JSON.
Starred by 102 users
Forked by 21 users
Languages ย  Haskell 88.8% | Shell 6.7% | JavaScript 4.5%
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ utilities โ€บ xml-to-json-converter
XML to JSON Converter - Free Online Tools %%page%% %%sep%% %%sitename%% - GeeksforGeeks
October 4, 2024 - Input XML: Provide the XML data you want to convert into JSON. Conversion: Click the "Convert" button to initiate the conversion process. Preview: Review the generated JSON output. Download: Optionally, download the converted JSON file.
Find elsewhere
๐ŸŒ
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.
๐ŸŒ
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
๐ŸŒ
Static.app
static.app โ€บ xml-to-json
XML to JSON Converter - Static.app
To convert XML to JSON, simply paste your XML data into the converter's text area or upload your XML file. Click the "Convert" button, and the tool will generate the corresponding JSON output. You can then copy the JSON or download the file for immediate use.
๐ŸŒ
JSONLint
jsonlint.com โ€บ xml-to-json
XML to JSON Converter - Transform XML Data Online | JSONLint | JSONLint
Convert XML to JSON instantly. Handles attributes, namespaces, and nested elements. Preview the result and copy or download the converted JSON.
๐ŸŒ
Microsoft Store
apps.microsoft.com โ€บ detail โ€บ 9p6pfjvgdmlx
Xml to Json Converter pro - Download and install on Windows | Microsoft Store
XML to JSON Converter Pro is a powerful and user-friendly tool that enables users to effortlessly convert XML files into the JSON format with high accuracy. This application is designed for developers, data managers, and anyone needing to transform ...
๐ŸŒ
n8n
n8n.io โ€บ tools โ€บ xml-to-json
XML to JSON Converter - Free and Easy Conversion | n8n
Easily convert XML to JSON for free. Paste XML plain text or upload XML file. Download or save JSON.
๐ŸŒ
Convertjson
convertjson.com โ€บ xml-to-json.htm
XML To JSON Converter
The tool will convert a XML file to JSON format.
๐ŸŒ
Oxygen XML
oxygenxml.com โ€บ doc โ€บ versions โ€บ 26.1 โ€บ ug-editor โ€บ topics โ€บ convert-XML-to-JSON.html
XML to JSON Converter
Discover the Oxygen JSON Editor! Tailored for Working with JSON and JSON Schema Documents Online XML to JSON Converter Attention: For a simple ONLINE tool for converting a single XML file to JSON, or ...
๐ŸŒ
Testsigma
testsigma.com โ€บ home โ€บ free tools โ€บ xml to json converter
Best Online XML to Json Converter | Testsigma
Convert XML to JSON effortlessly with our online tool. Streamline XML to JSON transformation and integration for seamless workflow. Try it now
๐ŸŒ
Conversion Tools
conversiontools.io โ€บ convert โ€บ xml-to-json
Convert XML to JSON Online | XML to JSON Converter
XML to JSON Converter. Convert XML to JSON Online with Free Converter. Import XML, Save JSON. XML conversion to JSON. API available.