N
NJHTools

XML Formatter

Paste XML to beautify it instantly with clean indentation, or minify it to one line. The validator pinpoints errors by line and column, and the converter turns XML into JSON and JSON back into XML. Free, no signup, and nothing is uploaded — it runs entirely in your browser.

XML output

Runs entirely in your browser. Your XML and JSON are never uploaded; only your options are remembered on this device.

How to format XML

  1. Paste or open your XML. Paste XML into the input box, open a .xml file from your device, or click Sample to try an example.
  2. Choose a mode. Pick Format to beautify, Minify to remove whitespace, Validate to check well-formedness, or XML → JSON and JSON → XML to convert.
  3. Adjust the options. Set a 2-space, 4-space or tab indent. For conversions, set the attribute prefix, the text node name, whether to parse numbers and booleans, and whether to always use arrays.
  4. Fix errors, then copy or download. If the XML is not well-formed, the error shows the line and column with a pointer to the problem. Otherwise copy the result or download it as .xml or .json.

Common XML errors and how to fix them

  • Mismatched or unclosed tag — every <item> needs a matching </item>, and tags must close in reverse order. Names are case-sensitive: <Item>doesn't close with </item>.
  • Unescaped special characters — write &amp; for & and &lt;for < in text, or wrap the text in <![CDATA[ … ]]>.
  • Unquoted or duplicate attributes — attribute values need quotes (id="1"), and each name can appear only once per element.
  • More than one root element — a document must have exactly one top-level element wrapping everything else.

XML to JSON mapping

XML has attributes, text and repeated elements, while JSON has only objects and arrays, so a converter needs a few conventions. This one uses the widely supported fast-xml-parser rules: attributes become keys with a prefix (@_id), text next to attributes goes under #text, and repeated elements become arrays. Because a single <book> becomes an object but two become an array, turn on Always use arrays when the shape must stay predictable for your code. The same conventions work in reverse for JSON → XML, so a round trip returns equivalent XML. Need YAML instead? Convert the JSON output with the JSON ↔ YAML converter.

Related tools

Frequently Asked Questions

How do I format XML online?↓

Paste your XML into the input box with Format selected. The beautified XML appears in the output as you type, one element per line and indented by nesting level. Choose 2 spaces, 4 spaces or tabs, then click Copy or Download .xml.

How do I check if my XML is valid?↓

Choose Validate and paste your XML. If it is well-formed you'll see Valid XML with counts of elements, attributes and nesting depth. If not, the error names the problem, such as an unclosed or mismatched tag, and shows the line and column with a pointer. This checks well-formedness; it doesn't validate against an XSD or DTD schema.

How do I convert XML to JSON?↓

Choose XML → JSON. Elements become keys, attributes become keys with the @_ prefix (you can change it), and text inside an element with attributes goes under #text. Turn on Always use arrays if your code expects repeated elements as lists even when only one is present.

How do I convert JSON to XML?↓

Choose JSON → XML and paste JSON. Keys become elements, keys starting with the attribute prefix become attributes, and arrays become repeated elements. If the JSON has more than one top-level key, it is wrapped in a root element whose name you can set.

Does formatting change my XML data?↓

Only whitespace between tags changes. Element names, attribute values, text, CDATA sections, comments and processing instructions are kept exactly. In mixed content, where text and child elements share a parent, each piece goes on its own line, so leave such documents unformatted if that whitespace matters.

Is my XML uploaded anywhere?↓

No. Formatting, validation and conversion all run in your browser with JavaScript, so you can safely use it on configuration files, API responses or SOAP messages. Only your options, such as indent and mode, are remembered on your device.

Last updated: