XML to JSON

Convert XML documents into JSON.

0 chars
0 words
0 lines
0 chars
0 words
0 lines

XML to JSON Converter Online

The XML to JSON converter turns XML documents into JSON that plugs directly into JavaScript, Python, or any REST API. Paste XML or open a file and the JSON updates as you type. Unlike one-size-fits-all converters, it lets you choose the mapping conventions so the output matches what your existing code or library already expects.

The mapping rules

  • The root element becomes the single top-level key.
  • Attributes become prefixed keys (@id, _id, -id, or $id).
  • Child elements become nested keys; repeated siblings become arrays.
  • Text in an element that also has attributes or children is stored under the text key (#text, _text, or value).
  • Empty elements become null.

Options explained

Detect numbers & booleans converts 44.95 to a number and true to a boolean, while leaving 007 or 2000-10-01 as strings. Remove namespace prefixes simplifies SOAP and feed documents. Ignore attributes keeps only element content for a leaner result. Always use arrays removes the classic XML-to-JSON ambiguity where a list with one item turns into an object — every child element becomes an array, so loops in your code never break. Indentation can be 2 spaces, 4 spaces, tabs, or minified for transport.

Compatibility with libraries

The default settings produce output in the style of fast-xml-parser and many online APIs. Choose _ and _text to approximate the xml-js compact format, or $-prefixed keys for tools influenced by the BadgerFish convention.

Edge cases

Comments and processing instructions are skipped. CDATA content is treated as text, and entities such as & are decoded. Mixed content (text interleaved with elements) keeps its trimmed text under the text key.

Convert back with JSON to XML, inspect the JSON in the JSON Viewer, or unwrap SOAP responses directly with SOAP to JSON. For other targets, see XML to YAML and the all-in-one XML Converter.

Frequently Asked Questions

As keys with a prefix, @ by default: <book id="bk101"> becomes {"@id": "bk101"}. You can switch the prefix to _, -, or $ to match what your library expects, or ignore attributes entirely.

A child element that appears once becomes a single value, and one that repeats becomes an array. If your code needs a predictable shape, switch on “Always use arrays for child elements” so that every child is wrapped in an array, even when it occurs only once.

Into the text key, #text by default: <price currency="USD">44.95</price> becomes {"@currency": "USD", "#text": 44.95}. Elements that have only text become plain values, and empty elements become null.

It turns qualified names like dc:creator or soap:Body into creator and Body, and drops xmlns declarations. That makes the JSON easier to use, but two elements with the same local name in different namespaces then share a key.