{<
Runs in your browserNothing is uploadedData, CSV & JSON

XML to JSON

Convert XML to JSON. Attributes go under "@attr", text under "#text", and repeated elements become arrays.

Loading tool…
Short answer

XML to JSON converts XML into JSON using the browser's own XML parser. Attributes go under "@attr", element text under "#text", and elements that repeat become arrays. Badly formed XML is rejected with the parser's message instead of being guessed at.

How does XML map to JSON?

Elements

Each child element becomes a key. An element with only text becomes a plain string, and one that appears several times becomes an array of values.

Attributes and text

Attributes are collected in an "@attr" object. When an element has attributes or children as well as text, the text goes under "#text".

Why use XML to JSON?

  • Use XML feeds in modern code. Turn RSS feeds, SOAP responses or exported XML into JSON that JavaScript and most APIs handle easily.
  • Strict parsing. Unclosed tags and other mistakes are reported, so you never get JSON built from broken input.
  • Private. Nothing is uploaded.

How to use XML to JSON, step by step

XML to JSON in PrintxPDF with a file loaded, options on the right and the run button below
XML to JSON with a file loaded: the steps below follow this screen.
  1. Paste XML into XML to JSON. The example is a small book catalogue with attributes and repeated elements.
  2. Choose whitespace handling. By default runs of spaces and line breaks in text are collapsed to single spaces.
  3. Copy or download the JSON. It updates as you type.

Frequently asked questions

Are values converted to numbers?

No. XML text has no types, so every value stays a string. This keeps codes and leading zeros intact.

What about comments and CDATA?

Comments and processing instructions are dropped. CDATA sections are read as normal text.

What happens to namespaces?

Prefixed names such as dc:title are kept as written, and xmlns declarations appear with the other attributes.

Looking for the long version? The guides cover each of these jobs in depth.