XML to JSON — Convert XML Data to JSON Format in Your Browser
Convert XML to JSON data. Configurable attribute handling, namespace stripping, and array detection. Runs entirely client-side — no uploads, no limits.
XML and JSON have been the two universal data interchange formats for the last quarter-century, and converting between them is a bridge between two technology stacks. JSON won the API era — it is the native format of JavaScript, the default for REST endpoints, and the lingua franca of configuration files. XML won the enterprise era — it is the format of SOAP, of document storage, of financial transaction messages, and of regulated-industry data exchanges where schema validation is a legal requirement. The conversion from XML to JSON is more art than science because XML has features that JSON cannot represent directly: attributes, namespaces, comments, processing instructions, and mixed content.
The attribute problem is the most visible. An XML element can carry both child elements (structured data) and attributes (metadata about the element), but JSON has no built-in distinction between data and metadata. Every XML-to-JSON converter solves this with a convention — a @ prefix for attributes, a separate metadata key, or attribute stripping — and no two converters agree on the right convention. This tool defaults to the @-prefix convention because it is the most widely used in the npm ecosystem (xml2js, fast-xml-parser), but the settings panel exposes all three options so the output matches whatever convention the downstream JSON consumer expects.
For a final hand-off: if the JSON output needs to become typed data for a programming language, feed it through one of the JSON-to-Code generators (JSON to TypeScript for frontend work, JSON to Go for backend services, JSON to Python for data pipelines). If the XML contained a formal schema, use the JSON Schema Generator to infer a JSON Schema from the output and validate future JSON payloads against the same constraints the XML schema enforced. If the destination is a configuration management system (Ansible, Kubernetes, Docker Compose), convert the JSON further to YAML with the JSON-to-YAML tool — YAML is the preferred configuration format for most DevOps tools.
How to use
Paste or drop your XML
Drop an XML string or file into the input. The parser validates XML syntax and reports any well-formedness errors inline. Valid XML proceeds to the conversion stage automatically.
Configure JSON conventions
Choose a convention for XML attributes (`@`-prefix, separate `$` object, or strip them), toggles for namespace prefix stripping, and array detection sensitivity. The default settings match the xml2js library conventions.
Copy or download the JSON
Copy the formatted JSON to your clipboard or download as a .json file. The output is pretty-printed with 2-space indentation for readability and diff friendliness.
Frequently asked
How does the converter decide what becomes a JSON array?
Repeating sibling elements with the same tag name become JSON arrays. A single `<item>` element is kept as an object unless 'force array' mode is enabled. The detection threshold can be adjusted to always treat certain tag names as arrays regardless of count.
What convention does the converter use for XML attributes?
The default is `@`-prefix: an XML `<book id="123">` becomes `{"book": {"@id": "123"}}`. Alternative conventions (a `$` wrapper object or stripping attributes entirely) are available in the settings. There is no single standard for attribute-to-JSON mapping — pick the convention that matches your downstream JSON consumer.
How are XML namespaces handled in the JSON output?
By default, namespace prefixes are stripped from element names after being used for scoping. `<ns:title xmlns:ns="http://example.com">` becomes just `"title"`. Enable 'preserve namespace prefixes' in the settings to keep `"ns:title"` as the key name.
What happens to XML text content inside elements with child elements?
Mixed content (an element containing both text and child elements) is handled with a `#text` key by default. `<para>Hello <b>world</b></para>` becomes `{"para": {"#text": "Hello ", "b": "world"}}`. Toggle 'merge text' in settings to combine adjacent text nodes.
Limitations
- XML schemas and DTDs are not processedThe converter ignores DOCTYPE declarations, internal DTD subsets, and XSD schema references. Entity declarations in the DTD (except the five pre-defined XML entities) will cause a parse failure.
- No CDATA distinction in outputCDATA sections are unwrapped and treated as regular text. The JSON consumer cannot distinguish content that was originally wrapped in `<![CDATA[...]]>` from regular text content.
- Processing instructions and comments are strippedXML processing instructions (`<?xml-stylesheet?>`) and comments (`<!-- comment -->`) are discarded during conversion. They have no direct JSON equivalent.
Platform notes
- macOS
- macOS ships with `plutil` which can convert plist XML to JSON but not generic XML. The browser tool handles arbitrary XML schemas and is the right pick for API response inspection.
- Linux
- CLI equivalent: `xmlstarlet` or `xq` (from yq) can convert XML to JSON. The browser tool is the right pick for XML pasted from a chat window or documentation page.
- Web
- All parsing and conversion runs in the browser. The XML content never leaves your device. Useful for converting confidential XML payloads without sending data to a server-side converter.