What is XML to JSON Converter?
This XML to JSON converter translates data between the two formats in both directions, and formats the JSON or XML output so it is easy to read. XML to JSON turns each element into a JSON property named after the element: text-only elements become string values, elements with children become nested objects, attributes become keys starting with @, and elements that repeat, such as several <item> entries, become an array. The root element becomes the top-level key.
JSON to XML does the reverse with the same conventions: object keys become elements, @ keys become attributes, a #text key becomes the element's text, arrays become repeated elements, and special characters are escaped so the result is always well-formed. It is a quick way to work with legacy SOAP and XML APIs from modern JavaScript code, or to produce XML for systems that still require it.
How to use XML to JSON Converter
- Choose XML → JSON or JSON → XML.
- Paste your XML or JSON into the input panel.
- Read the converted result in the output panel; JSON output can be explored as a tree.
- Copy or download the result.
Key features
- XML to JSON and JSON to XML
- Attributes converted to @name keys and back
- Repeated XML elements become JSON arrays
- Special characters escaped so the XML output is always well-formed
- Adds the XML declaration and a root element when needed
- Runs entirely in your browser
Common use cases
- Consuming SOAP and legacy XML APIs from JavaScript
- Converting RSS feeds and sitemaps into JSON for processing
- Producing XML payloads from JSON data for older integrations
- Migrating XML configuration to JSON
- Inspecting XML data structures in a JSON tree
Technical details & standards
XML is parsed with the browser's DOMParser, so it must be well-formed; otherwise the parser's error is shown with its line and column. Each element becomes a key, attributes become @name keys, and repeated sibling elements become arrays. An element with only text becomes a string; when an element has attributes or child elements as well as text, the text is stored under #text. CDATA sections are read as text, namespace prefixes such as soap:Body are kept in the names, and comments and processing instructions are dropped. All values are strings, because XML has no number or boolean types.
JSON to XML writes each key as an element and each array item as a repeated element named after the array's key; null, empty strings and empty objects become self-closing elements. Text is escaped (& becomes &, < becomes <, > becomes >), attribute values also escape quotes, and keys that are not valid XML names, such as "first name" or "1st", are turned into valid ones (first_name, _1st). If the JSON object has a single top-level key it becomes the root element; otherwise everything is wrapped in <root>, and a top-level array becomes <root> with one <item> per entry.
Frequently asked questions
How are repeated XML elements converted?
Sibling elements with the same name become a JSON array. For example two <tag> elements under <tags> become "tags": { "tag": ["a", "b"] }.
What happens to XML attributes?
Each attribute becomes a key with an @ prefix, so <price currency="USD">9.99</price> becomes "price": { "@currency": "USD", "#text": "9.99" }. Converting that JSON back to XML restores the attribute.
Why are numbers strings in the JSON?
XML has no data types: everything is text. The converter keeps values as strings rather than guessing, so convert numbers and booleans in your code where you know the schema.
How do I convert XML to JSON in code?
In JavaScript use fast-xml-parser or xml2js; in Python use xmltodict (json.dumps(xmltodict.parse(xml))); on the command line, yq -p=xml -o=json file.xml.
Is my data safe?
Processing happens locally in your browser. Tool input is not sent to CodeUnpack servers.
Does it work offline?
Once the page has loaded, this tool can process input without an internet connection.