XML Formatter & XML to JSON
Pretty print or minify XML, spot syntax errors, and convert XML to JSON. Everything runs in your browser and nothing is uploaded.
How to use XML Formatter & XML to JSON Converter on KickSolve
Three quick steps, no account needed.
Why choose KickSolve
Built for speed, privacy and clean results.
What you can do with XML Formatter & XML to JSON Converter
Everything this tool is good for.
About XML Formatter & XML to JSON Converter on KickSolve
What it does, how it works and how to get the best results.
What an XML formatter does
It parses your XML and writes it back with consistent indentation, so the hierarchy of elements is visible. Whitespace between tags is normalised, but names, attributes and text are kept. The declaration, comments, CDATA sections and processing instructions are preserved.
Checking for errors
The parser reports the first problem it finds, such as a mismatched closing tag, an unquoted attribute or an unescaped ampersand. Fix it and the message updates immediately. The result is well-formedness checking, not validation against a schema.
How XML becomes JSON
Each element becomes a key under its parent. Attributes are written as keys starting with @, text next to attributes or child elements goes in #text, and a tag that repeats becomes an array. Elements that only contain text become plain strings.
A common gotcha
A tag that appears once is a single value, and the same tag appearing twice is an array. If your code expects an array, handle both cases, or make sure the sample you convert contains the repeated element.
Related tools
After converting, tidy the result with the JSON Formatter, query it with the JSONPath Tester, or switch formats with JSON to YAML.
Worked example: XML to JSON
Attributes, text and a repeated tag.
XML:
<library name="City">
<book id="1">Dune</book>
<book id="2">Emma</book>
</library>
JSON:
{
"library": {
"@name": "City",
"book": [
{"@id": "1", "#text": "Dune"},
{"@id": "2", "#text": "Emma"}
]
}
}The repeated book tag became an array, the attributes got an @ prefix and the text went into #text.
XML to JSON mapping
How each part of XML appears in the JSON.
| XML | JSON |
|---|---|
Attribute id="1" | Key "@id": "1" |
| Element with text only | A plain string value |
| Text plus attributes or children | Key "#text" |
| Repeated tag | An array of values |
| Empty element | An empty string |
| CDATA | Text value |
Frequently asked questions
Quick answers.
How do I format XML online?
Paste your XML, keep Format selected and choose an indent. The formatted XML appears as you type, and you can copy or download it.
How do I find the error in my XML?
The status line shows the parser’s message. Common causes are mismatched tags, unquoted attributes, unescaped & or < characters and more than one root element.
How does XML to JSON work here?
Attributes become @name keys, text next to attributes or children becomes #text and repeated tags become arrays.
Why is one of my elements not an array?
A tag that appears only once is converted to a single value. Only repeated tags become arrays, so handle both cases in your code.
Does it keep comments and CDATA?
In Format and Minify modes yes. Comments, CDATA sections, processing instructions and the XML declaration are preserved.
Does it validate against an XSD or DTD?
No. It checks that the XML is well-formed, not that it follows a schema.
Can I convert JSON back to XML?
Not on this page. For JSON tidying and validation use the JSON Formatter.
Is my XML uploaded?
No. Parsing and conversion use your browser’s built-in XML parser and nothing is sent to a server.
More free tools from KickSolve
Related free tools. Each one runs in your browser too.