XML → JSON

    About this tool

    This tool converts XML to JSON right in your browser, for example RSS feeds, SOAP responses, configuration files or exports. It also checks whether the XML is well-formed and shows the first error with line, column and a marked spot. Because XML and JSON are built differently, you can set the mapping, such as attribute prefix, lists and namespaces. The reverse direction, JSON → XML, is available too. All data stays in your browser; nothing is sent.

    What you can use it for

    Frequently asked questions

    How do I convert XML to JSON?

    Paste XML into the input field, drop a file in or pick an example. The JSON appears next to it right away and can be copied or downloaded as a .json file. The settings control how attributes, text and lists look.

    Why is there no single correct way to convert XML to JSON?

    XML has attributes, order, text between elements, comments and namespaces, while JSON only has objects, lists and simple values. There is no standard for this and libraries choose differently. The tool therefore shows the chosen convention and its effect on examples.

    What does well-formed XML mean?

    There is exactly one root element, all tags are closed and nested correctly, attributes are quoted and unique, and only allowed characters appear. Well-formed is not the same as valid: checking against an XSD or DTD does not happen here.

    How do I find the error in my XML?

    The tool reports the first error with line, column, a marked spot and an explanation. “Go to error” jumps there. After fixing it, another error may follow.

    How are XML attributes shown in JSON?

    By default with the prefix @ (@name). You can choose _ as the prefix or omit attributes. Text in elements that have attributes or children is stored under a text key, #text by default.

    Is my data uploaded?

    No. The conversion runs entirely in your browser. The link button contains only settings, never the data. Input can be up to 5 MB.

    Can I convert JSON back to XML?

    Yes, using the “JSON → XML” direction. Keys with the attribute prefix become attributes, the text key becomes content, and lists become repeated elements. Using the same settings as for the forward direction gets you closest to the original.

    Are DTD entities resolved?

    No. A DOCTYPE declaration is read and skipped; entities defined in it are neither resolved nor fetched. This rules out attacks such as “billion laughs” and XXE. References to them are reported as errors.

    Background

    XML and JSON are both formats for structured data, but they model different things. JSON consists of objects, lists, strings, numbers, booleans and null. XML has elements with attributes, text between elements, comments, CDATA sections, processing instructions and namespaces, and the order of nodes is part of the document. That is why there is no standard for converting between them. Libraries such as xml2js, fast-xml-parser, Badgerfish or Parker each follow their own rules.

    Typical points of dispute are what an attribute is called in JSON, how a single child element is treated and how an empty element is shown. Common choices are prefixes like @ or _ for attributes and keys like #text or $ for text. Repeated elements under the same parent usually become a list. The catch: the same schema yields an object or a list depending on the data. “Always list” avoids this but makes the output longer.

    Mixed content, such as <p>Hello <b>world</b> there</p>, cannot be mapped to JSON without loss, because objects have no such ordering. For genuine text documents like HTML, JSON is the wrong format. Namespaces involve a choice too: keeping them carries prefixes and xmlns declarations over, removing them is more readable but can make names collide.

    Before conversion the XML must be well-formed. That means one root element, correctly closed and nested tags, quoted attributes, no duplicate attributes, only allowed characters and declared namespace prefixes. The tool reports the first error with line and column. Well-formed does not mean valid against a schema; XSD and DTD are not evaluated.

    For security, DTD entities are neither resolved nor loaded from outside. This prevents attacks such as “billion laughs” and XXE. Processing happens entirely in the browser.

    The round-trip check converts the XML to JSON and back and compares both documents, ignoring unimportant differences. This shows whether the chosen convention changes content. It cannot be performed when namespaces are removed or attributes are omitted.

    Help & info

    Why XML → JSON is not unambiguous

    XML has attributes, order, text between elements, comments and namespaces; JSON only objects, lists and simple values. There is no standard for this: xml2js, fast-xml-parser, Badgerfish or Parker each choose differently. Typical points of dispute: what is an attribute called in JSON? Does a single child become a list? What happens to an empty element? This tool shows its choice — the table in the settings shows live what the current convention does.

    Lists and repetition

    Default: a name that occurs several times under the same parent becomes a list; a single child stays a single value. The catch: the same schema yields a list or an object depending on the data. “Always list” makes every child a list — more stable for programs, but longer. If elements of the same name are not adjacent (a b a) they are bundled; the order relative to b is lost, and the tool says so.

    Mixed content

    In <p>Hello <b>world</b> there</p> text sits between elements. JSON objects have no such order: the text is joined (“Hello there”) and placed before the children. The tool reports every mixed-content element and the “Round trip” figure shows that going back changes the document. For real text documents (HTML, Word XML) JSON is the wrong format.

    Namespaces

    “Keep” carries prefixes and xmlns declarations as names and attributes (p:item, @xmlns:p). “Remove” cuts the prefixes and drops xmlns attributes — more readable but lossy: if two elements then share a name they become a list. Parsing checks that every prefix is declared (otherwise an error, like expat and libxml2).

    CDATA, comments, instructions

    CDATA sections are just another spelling of text and are merged with normal text by default. With “own key” they stay separate (#cdata) and become CDATA again on the way back. Comments appear in the JSON only on request (#comment). Processing instructions (<?…?>), DOCTYPE and the XML declaration have no place in JSON; going back, the declaration is generated anew.

    Checking well-formedness

    Well-formed means: exactly one root element, every tag closed and nested correctly, attributes quoted and unique, only allowed characters, < & > only as syntax or entities, no “--” in comments, undeclared namespace prefixes are errors. The parser reports the first error with line, column and a marked spot. Well-formed is not valid: checking against a schema (XSD, DTD) does not happen here.

    DTD and entities (security)

    A DOCTYPE declaration is read and skipped. Entities defined by a DTD (<!ENTITY …>) are not resolved and never fetched from outside: this rules out “billion laughs” and XXE (file or network access through SYSTEM entities). References to them count as the error “Unknown entity”.

    Limits & privacy

    Everything runs in your browser, nothing is sent; the link button contains only settings, never your data. Input up to 5 MB, nesting up to 400 levels. Large trees are built row by row (a few thousand rows at a time); copy and download always deliver the full text.

    ⚠️ Bitte beachten

    Die Werkzeuge auf dieser Website werden als kostenloses Hobbyangebot bereitgestellt und dienen ausschließlich zur Information und privaten Nutzung. Für die Richtigkeit, Vollständigkeit oder Eignung der Ergebnisse für einen bestimmten Zweck wird keine Gewähr übernommen. Vor Verwendung der Ergebnisse — insbesondere bei finanziellen, rechtlichen oder sicherheitsrelevanten Entscheidungen — sind diese eigenverantwortlich zu prüfen. Eine Haftung für Schäden aus der Nutzung ist ausgeschlossen, soweit dies gesetzlich zulässig ist.