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
XML to JSON is very unique tool for convert JOSN to XML and allows to download, save, share and print XML to JSON data..
๐ŸŒ
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.
๐ŸŒ
JSON Formatter
jsonformatter.org โ€บ xml-formatter
Best XML Formatter and XML Beautifier
Free XML Formatter also works as XML Converter / Convertor to JSON.
๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
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.
Find elsewhere
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.

๐ŸŒ
Online XML Tools
onlinexmltools.com โ€บ convert-xml-to-json
Convert XML to JSON - Online XML Tools
Free online XML to JSON converter. Just paste your XML in the form below and it will automatically get converted to JSON. There are no ads, popups or nonsense, just an awesome XML to JSON converter. Paste XML, get JSON.
๐ŸŒ
JSON Formatter
jsonformatter.org โ€บ xml-to-jsonschema
Best XML to Jsonschema Converter
Load Data XML to Jsonschema Download ยท ร— ยท Load URL ยท Upload File ยท Close ยท ร— ยท DownloadUpdateSave OnlineCloseErrorDialog ยท
๐ŸŒ
JSON Formatter
jsonformatter.org
Best JSON Formatter and JSON Validator: Online JSON Formatter
Online JSON Formatter / Beautifier and JSON Validator will format JSON data, and helps to validate, convert JSON to XML, JSON to CSV. Save and Share JSON
๐ŸŒ
Oxygen XML
oxygenxml.com โ€บ doc โ€บ versions โ€บ 28.0 โ€บ ug-developer โ€บ topics โ€บ convert-XML-to-JSON-x-tools.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 ...
๐ŸŒ
GS Plugins
gsplugins.com โ€บ tools โ€บ xml-to-json
XML to JSON - GS Plugins
July 23, 2025 - XML to JSON โ€“ Easily convert XML data to JSON format in seconds. Simple, fast, and hassle-free transformation for developers and data processing.
๐ŸŒ
Microsoft AppSource
appsource.microsoft.com โ€บ en-us โ€บ product โ€บ web-apps โ€บ systoolssoftwareprivatelimited1632140387066.xml-to-json-converter
SysTools XML to JSON Converter
This software is the best option for anyone interested in converting XML to JSON quickly and easily. This tool will help you quickly and accurately convert the appropriate XML file to JSON format with an intuitive UI, fast processing of the XML files, and smart data mapping.
๐ŸŒ
JSON Formatter
jsonformatter.org โ€บ json-to-xml
Best JSON to XML Converter
JSON to XML is very unique tool for convert JOSN to XML and allows to download, save, share and print JSON to XML data..
๐ŸŒ
Convertjson
convertjson.com โ€บ xml-to-json.htm
XML To JSON Converter
The tool will convert a XML file to JSON format.
๐ŸŒ
JSON Formatter
jsonformatter.org โ€บ xml-pretty-print
Best XML Pretty Print Online
Ad blocking? It's okay. Please share to support us: ... XML Pretty Print helps Pretty XML data and Print XML data.