فارسی

Format, Validate, and Convert XML Online

Pretty-print or minify XML, find a syntax error by line and column, and convert to JSON or back. Everything runs in your browser.

Use this tool in your browser without installing software.

About this tool

This page does three jobs. In Format mode it lays the document out with readable indentation, or with Minify checked it removes the whitespace between tags. In XML → JSON mode it turns the document into a JSON object, and in JSON → XML mode it turns that shape back into XML. If the document is malformed, no output is produced: instead of a generic message you get the line, the column, and that source line with a ^ marker. Formatting preserves comments, CDATA sections, <? ?> instructions and the DOCTYPE, and leaves text inside elements untouched; an element that holds text next to child elements (mixed content) deliberately stays on one line so indentation cannot add whitespace to the text. In JSON, attributes are stored under @ and text under #text, repeated names become arrays, and the same rules are read on the way back. The document is checked for well-formedness only, not against a DTD or XSD. Nothing is uploaded and your text never leaves the browser.

How to use it

  1. 1

    Paste XML or JSON into the input box, or pick a file with Open. The conversion direction is also guessed from the file extension.

  2. 2

    Choose a mode at the top: Format, XML → JSON, or JSON → XML. The result appears as you type, and any error is listed under the boxes.

  3. 3

    Copy the result or download it. To go back, press Reverse and the result becomes the new input.

If the file will not open

  • I get “unknown entity” for &nbsp; or &copy;.

    Those names are not defined in XML. Use numeric references instead: &#160; for a non-breaking space and &#169; for ©. If the document has a DOCTYPE that declares entities, keep that DOCTYPE and open the file with it.

  • It says a closing tag does not match the open one.

    Usually one element is closed in the wrong order. Look at the line and column under the message and at the marked source line: the closing tag must match the most recent open tag exactly. XML is case-sensitive.

  • A single element did not become an array in the JSON.

    An array appears only when the same name repeats. If your code always expects an array, wrap the single value yourself or add another element to the document.

  • The order of text and elements is lost in the JSON.

    JSON has no natural place for mixed content, so the text is collected under #text. If the exact order matters, use Format mode, which leaves the document untouched.

Frequently asked questions

Why does an element with text and child tags stay on one line?

That is deliberate. When text sits next to an element, breaking the line and indenting it would add whitespace that the text never had and change the meaning. The formatter only breaks lines where there is no meaningful text, so mixed content is left exactly as it was.

Why do I see keys like @id and #text in the JSON?

JSON has no standard way to express XML attributes. This tool stores attributes under @, an element’s text under #text, and repeated names as arrays. The same mapping is read on the JSON → XML side, but mixed text and element order cannot be preserved in JSON.

Why is leading and trailing text whitespace gone in the JSON?

Indentation whitespace between tags is not real text; keeping it would fill the JSON with spaces and line breaks. Only the start and end of each text run are trimmed; spaces inside the text stay. If leading whitespace matters to you, keep the original XML.

Do you validate against a DTD or XSD?

No. This tool checks well-formedness only: open and closed tags, quoted attributes, entities and a single root. DTD or XSD validation needs external definitions and does not happen here. The DOCTYPE is preserved in the output, but its contents are not executed.

Why does &nbsp; fail while &amp; works?

XML has exactly five predefined entities: amp, lt, gt, quot and apos. Everything else, including nbsp, must be declared in a DTD or written as a numeric reference, for example &#160; instead of &nbsp;. Files that came from HTML usually need those numeric codes.

Can I open a multi-megabyte document?

Up to about 5 MB. All the work happens in your browser, so the limit keeps the page from freezing on weaker devices. For larger files, split the document or use a command-line tool.