DT Dev Tools

XML to JSON Converter

Convert XML to JSON online with attributes, repeated elements as arrays, typed numbers and booleans and clear error positions. Free, instant and private in your browser.

πŸ”’ Runs entirely in your browser β€” nothing is uploaded

Advertisement

Convert XML to JSON in your browser

Plenty of systems still speak XML β€” SOAP services, RSS and Atom feeds, sitemaps, Maven and .NET project files, invoices, bank exports β€” while most modern code prefers JSON. This XML to JSON converter bridges the two. Paste a document and every element becomes a JSON key, nested elements become nested objects, and siblings that share a name are collected into an array. The XML declaration and processing instructions are skipped, whitespace around text is trimmed, and the output is pretty-printed with the indentation you choose so it is easy to read and diff.

The input is validated before conversion. If a tag is not closed or an attribute is malformed, you get the parser message together with the line and column, which makes it quick to fix copy-and-paste mistakes before they reach your code.

Attributes, text and types

XML has concepts JSON lacks, so the converter follows a widely used convention. Attributes are written as keys with a prefix β€” @ by default β€” and text inside an element that also has attributes is placed under #text. Pick a different prefix such as _ or $ if your code expects one, or untick Keep attributes to drop them for a simpler structure. With Convert numbers and booleans enabled, values like 42, 9.99 and true become real JSON numbers and booleans; turn it off to keep every value as a string, which is safer for IDs with leading zeros or long numeric codes.

Tips for reliable conversions

XML does not say whether an element is a list, so an element that appears once becomes an object, and the same element appearing twice becomes an array. If your code always expects an array, normalise those fields after parsing or test with a sample that contains several items. Namespace prefixes such as soap:Envelope are kept as part of the key. Conversion runs locally with the fast-xml-parser library, so confidential documents never leave your device β€” and you can go the other way with the JSON to XML converter.

How to use

  1. Paste XMLPaste an XML document or click Load sample.
  2. Set optionsChoose the attribute prefix, indentation and whether to convert numbers and booleans.
  3. Copy the JSONCopy the result or download it as a .json file.

Frequently asked questions

How are XML attributes represented in JSON?
Attributes become keys with a prefix, @ by default, so <book id="1"> turns into "@id": 1. Change the prefix, or untick Keep attributes to drop them.
What happens to repeated elements?
Sibling elements with the same name become a JSON array. A single element stays an object, so check list-like fields when a sample only contains one item.
Where does text go when an element also has attributes?
It is stored under a #text key next to the attribute keys, for example {"@currency": "USD", "#text": 9.99}.
Is my XML uploaded?
No. Parsing and conversion run entirely in your browser with fast-xml-parser.
Advertisement