XML to JSON Converter
Paste XML and see it as JSON immediately. Attributes are kept as @-prefixed keys, text as #text, and repeated tags are grouped into arrays. Parse errors are reported clearly.
Runs in your browser. Your files are never uploaded.
Loading XML to JSON Converter…
How to use XML to JSON Converter
- Paste your XML into the left box, or press Load sample.
- Optionally tick Convert numbers and true/false to turn text like 42 or true into real JSON values.
- Check the JSON on the right. If the XML is malformed, an error message explains the problem.
- Copy the result or download it as a .json file.
What this converter does
XML is a tree of elements, attributes and text. JSON is a tree of objects, arrays and values. They overlap heavily but are not identical, so any converter has to choose conventions. This tool uses a widely used one: attributes are prefixed with @, text that sits next to attributes or children is stored as #text, and repeated sibling tags become an array.
The result is wrapped in an object keyed by the root element name, so the output always shows which element the document started with.
Typical uses
- Reading an XML API or feed response in a JavaScript or Python project that prefers JSON.
- Understanding the shape of a large XML export before writing parsing code.
- Converting configuration or sitemap-like data for use in scripts.
- Checking quickly whether an XML snippet is well-formed.
- Preparing test fixtures when a service moves from XML to JSON.
Things to know
Whitespace-only text between elements is ignored, and surrounding whitespace in text values is trimmed. CDATA sections are treated as ordinary text. Comments and processing instructions are dropped, and XML namespaces are kept as part of the tag name, so a tag like dc:title stays dc:title.
By default every value is a string because XML has no data types. Turn on number and boolean conversion if you want 42 and true converted to JSON types, but be careful with identifiers such as zip codes or phone numbers where leading zeros matter; the converter only converts values that look like plain numbers without leading zeros. The tool does not validate against a schema (XSD or DTD); it checks only that the XML is well-formed. Everything is processed locally in your browser.
Why use this xml to json converter tool
- Native parser. Uses the browser’s built-in DOMParser, the same strict XML parser web pages use, so malformed XML is rejected rather than guessed at.
- Attributes preserved. Each attribute becomes a key starting with @, so nothing is silently dropped.
- Repeated tags become arrays. Sibling elements with the same name are grouped into an array automatically.
- No upload. Parsing is done on your device. Your XML never leaves the page.
Frequently asked questions
How are attributes and text represented?
Attributes become keys prefixed with @, for example @id. If an element has both attributes or child elements and some text, the text is stored under the key #text. An element with only text becomes a plain string value.
Why does a single child sometimes appear as an object and sometimes as an array?
XML does not say whether an element may repeat, so the converter only creates an array when the same tag appears more than once under the same parent. If your consuming code expects an array, wrap single values in a list after conversion.
Why does the tool say my XML is not well-formed?
Common causes are a missing closing tag, an unescaped & or < in text, mismatched tag case (XML is case-sensitive), unquoted attribute values, or more than one root element. The message from the parser points to the line and column of the first error.
More free tools
JSON Formatter
Format, validate, beautify and minify JSON instantly. Shows the exact line and column of any error. Free and runs in your browser.
Open toolJSON to CSV
Convert a JSON array to CSV in your browser. Flattens nested objects, picks delimiters and downloads a ready .csv for Excel or Sheets.
Open toolCSV to JSON
Convert CSV to JSON in your browser. Auto-detects delimiter, uses the header row as keys, and can convert numbers and booleans.
Open tool