{ }JSONKit.tools

XML to JSON Converter

Paste XML and get JSON back, with attributes kept as @-prefixed keys and repeated elements collected into arrays. Invalid XML is reported with a line and column.

XML → JSON⇄JSON → XML

XML

JSON

Waiting for input…

About this tool

XML carries two kinds of data that JSON has only one slot for: child elements and attributes. This converter keeps both by prefixing attribute names with @, so nothing is lost and the two stay distinguishable. Repeated sibling elements collapse into an array, because JSON cannot repeat a key. The document is validated before it is parsed, so a mismatched tag gets you a line number instead of a half-converted object.

How to use it

  1. 1Paste an XML document into the left panel.
  2. 2Read the JSON on the right — attributes appear as @name keys.
  3. 3Switch the output to Tree to fold deep documents, or press Copy.

Frequently asked questions

›What happens to XML attributes?

They become keys prefixed with @ on the same object as the element, so <user id="7"> turns into { "user": { "@id": "7" } }. Nothing is dropped, and you can tell an attribute from a child element at a glance.

›Why did my repeated elements become an array?

Because JSON has no way to repeat a key. One <item> is an object; two or more become an array of objects. This is the one place where the same schema can produce different JSON shapes depending on the data.

›Is the conversion reversible?

Mostly. Elements, attributes and text survive the round trip. What does not: comments, processing instructions, namespace declarations as such, and the difference between an empty element and an empty string.

›What counts as invalid XML here?

Unclosed or mismatched tags, more than one root element, stray < or & in text, and unquoted attribute values. The error names the line and column so you can jump straight to it.

›Are numbers in the XML converted?

Yes. Text that is a valid number or boolean becomes a JSON number or boolean rather than a quoted string, which is usually what you want when feeding the result to code.