XML to JSON Converter
Transform XML documents into structured JSON with attribute & element handling
Read XML as JSON
JavaScript, REST clients and many databases handle JSON far more easily than XML. This converter parses the XML you paste, using the browser's own XML parser, and rebuilds it as a JSON object that follows the same hierarchy. A badge tells you whether the XML was accepted as valid.
Step by step
- Paste XML into XML Input, or press Sample to load a small store with products, prices and tags.
- Pick an Indentation of 2 spaces, 4 spaces or Minified.
- Choose Attribute Handling, described below.
- Tick Force Arrays if you want every child element wrapped in an array, even when it appears only once.
- Press Convert to JSON, then Copy or download output.json. The stats bar lists input bytes, output bytes and the number of top-level keys.
Three ways to treat attributes
- Prefix with @ writes each attribute as a key such as @id beside the child elements.
- Nest in _attr gathers all attributes into a single _attr object, which keeps them separate from element names.
- Flatten (ignore) drops attributes entirely.
An element that has both text and attributes stores the text under a #text key. An element with only text becomes a plain string, and an empty element becomes null.
Repeated elements and arrays
When siblings share a name, like several product elements, they are combined into a JSON array automatically. A single product would normally appear as an object rather than a one-item array, which can break code that expects a list. Force Arrays avoids that inconsistency by always producing arrays for children.
Practical scenarios
- Reading an RSS or Atom feed, or a sitemap, in a JavaScript project.
- Migrating data from a SOAP-era service to a JSON-based API.
- Inspecting a complex configuration file as a collapsible JSON tree in your editor.
- Writing test fixtures from real XML samples.
Things to remember
The root element name becomes the top-level key of the result. All values stay as strings; numbers such as 149.99 or flags such as true are not converted. Comments and processing instructions are ignored. Invalid XML displays the parser's error in the output box with an invalid indicator.
Because the result is built from the XML you paste, you can keep pasting revised versions and converting again until the structure suits the code that will consume it.
Related Articles
Related Tools