XML to JSON
Convert XML to JSON in your browser. Attributes become @-prefixed keys and repeated elements become arrays. Errors show line and column; pick 2, 4 or tab indents.
About XML to JSON
The XML to JSON converter parses an XML document and writes the same data as a JSON object, indented with 2 spaces, 4 spaces or tabs. It is useful when an older API, feed or export produces XML but the code you are writing, or the tool you are feeding, expects JSON.
The mapping is predictable: each element becomes a key, attributes become keys prefixed with @, repeated sibling elements become arrays, and the text of an element that also has attributes is stored under #text. The document is checked for well-formedness first, so malformed XML produces an error with its line and column instead of partial JSON.
How to use XML to JSON
- Paste XML into the input box, or open or drop an .xml file.
- Choose 2 spaces, 4 spaces or Tabs for the JSON indentation.
- Review the JSON output, or fix the reported line and column if the XML is not well formed.
- Copy the JSON or download it as a .json file.
Features
- Maps attributes to @name keys, and element text to #text when the element has attributes.
- Turns repeated sibling elements into JSON arrays; empty elements become empty strings.
- Keeps all values as strings, so 007 and 1.50 are not turned into numbers.
- Decodes entities such as & and includes CDATA content as plain text.
- Drops comments and the XML declaration, and trims whitespace around text.
Common uses
- Consuming a SOAP or legacy XML API from JavaScript code.
- Inspecting RSS, Atom or sitemap data with JSON tools such as jq.
- Migrating XML configuration to a JSON-based format.
- Creating JSON test fixtures from sample XML responses.
Tips
- An element that appears once becomes a single value, but the same element repeated becomes an array. If your code expects a list, handle the single-item case too.
Frequently asked questions
How are XML attributes represented in JSON?
Each attribute becomes a key with an @ prefix. For example, <item id="7">Pen</item> becomes {"item": {"#text": "Pen", "@id": "7"}}. An element with text and no attributes becomes a plain string, such as {"name": "Pen"}.
Why are numbers in the JSON output strings?
XML has no data types: 42 inside an element is just text. The converter keeps values as strings to avoid altering IDs, postal codes or decimal amounts. Convert specific fields to numbers in your own code where you know the intended type.
Why is one element an array and another an object?
Repeated sibling elements with the same name are collected into an array, while a single occurrence stays a single value. This mirrors the XML, but it means the shape can change between documents, so code that reads the result should accept both forms.
What happens to namespaces?
Namespace prefixes are kept as part of the key, so <dc:creator> becomes the key dc:creator, and xmlns declarations appear as @xmlns attributes. Prefixes are not resolved to namespace URIs.
Are comments and CDATA sections preserved?
Comments are dropped because JSON has no equivalent. CDATA sections are included as ordinary text in their element’s value, so <d><![CDATA[x<y]]></d> becomes "d": "x<y".
Can I convert XML to JSON online for free without signing up?
Yes. Use this tool without an account or payment. Files are processed in your browser. Download the result after processing; supported formats and browser requirements are described above. Conversion can change quality, transparency or layout depending on the formats.
Is my input uploaded?
Tools run in your browser. Files, text and results are not uploaded to our servers and are cleared when you leave the tool.
Your privacy comes first
Tools run in your browser. Files, text and results are not uploaded to our servers and are cleared when you leave the tool.