Convert XML into clean JSON for APIs, apps, and scripts. Paste your XML or choose a file, pick your settings, and copy or download the result. The conversion happens in your browser, so your data stays on your device and is not uploaded to our servers.

Converting XML to JSON is useful when you read a feed or configuration file in a web app, work with an older API that returns XML, or hand data to a developer who works with JSON.

How to convert XML to JSON

  • Add your XML: paste it into the box, or click the drop zone to choose an XML or TXT file. Press Try an example to see how it works.
  • Choose how to treat attributes: include them as keys that start with @, or ignore them.
  • Choose whether to keep the root element: include it as the top-level key, or skip it to start with the contents.
  • Choose how to treat values: Detect types turns plain numbers and true or false into JSON numbers and booleans, and Keep as text leaves everything as text.
  • Convert and save: press Convert to JSON, check the preview, then copy the JSON or download it as a file.

Settings options

SettingChoicesWhat it does
AttributesInclude as @keys, IgnoreInclude adds each attribute as a key that starts with @. Ignore leaves attributes out of the JSON.
Root elementInclude root, Skip rootInclude root wraps the output in the root element name. Skip root outputs only what is inside it.
ValuesDetect types, Keep as textDetect types turns plain numbers and true or false into JSON numbers and booleans. Keep as text leaves every value as text.
FormattingPretty, MinifiedPretty adds line breaks and indents for easy reading. Minified makes the smallest output.

How XML becomes JSON

XMLExampleResult
Element with text<name>Ana</name>Becomes "name": "Ana" in the parent object.
Attribute<person id="1">Becomes "@id": 1 when Include as @keys is on.
Repeated elementTwo <person> tags in one parentBoth go into one list under the key person.
Empty element<city/>Becomes an empty text value.
Text and attribute<price currency="PHP">250</price>The text is stored under #text next to the attribute key.
Namespace<ns:item>The key keeps the prefix, such as "ns:item".

What this tool does and does not do

The tool reads XML with your browser's built-in parser and turns each element into a JSON object or value, using the settings you choose. Text is trimmed of spaces at the start and end, and CDATA sections are read as text. Comments and processing instructions are skipped. Repeated element names under the same parent become a list, but a single element stays as one value, so the shape can change between documents. Detect types only converts plain numbers without leading zeros and with up to 15 digits, plus the words true and false, so values such as 00123 and very long IDs stay as text. Dates stay as text, and empty elements stay as empty text instead of null. The tool does not check the XML against a schema such as an XSD or DTD, and it does not fetch external references. Save XML as UTF-8 so accented characters are kept. Your original file is not changed.

Tips for better results

  • Check the root element: if the output has one extra level, switch to Skip root.
  • Keep attributes for IDs: attributes such as id or type often carry important values, so include them unless you do not need them.
  • Use Keep as text for codes: ZIP codes, phone numbers, and IDs stay exactly as written.
  • Check the preview: it shows the start of the JSON so you can confirm the keys and values before you download.
  • Validate the XML first: if you get an error, check that every opening tag has a matching closing tag.
Converting XML to JSON turns nested markup into data that web apps, APIs, and scripts can read directly.

Common XML to JSON problems

  • Invalid XML: a tag is not closed, two tags overlap, or an attribute value is missing its quotes. The message under the result gives the line number when the browser provides one.
  • Attributes are missing: the Attributes setting is set to Ignore. Choose Include as @keys.
  • The output has an extra level: the root element is included. Choose Skip root to remove it.
  • A value lost its zeros or became a number when it should not: choose Keep as text to leave every value exactly as written.
  • Keys have a colon in them: the XML uses namespace prefixes. The prefix is kept in the key name, such as ns:name.
  • The file was not added: only XML and TXT files up to 5 MB are accepted. Pasting smaller parts of the data also works.

Frequently asked questions

How do I convert XML to JSON for free?

Paste your XML or choose an XML file, pick your settings, press Convert to JSON, then copy or download the result. No account or software is needed.

Is my XML uploaded to a server?

No. Your XML is read and converted in your browser and stays on your device during conversion.

How are attributes shown in the JSON?

With Include as @keys selected, each attribute becomes a key that starts with @, such as @id, and is added to the object for its element. With Ignore selected, attributes are left out.

What happens when an element repeats?

When the same element name appears more than once under the same parent, its values are placed in a list. A single occurrence stays as one value, so the shape can differ between documents.

How are text and empty elements handled?

An element with only text becomes that text as its value. An empty element becomes empty text. If an element has attributes and text, the text is stored under the key #text.

Does the tool detect numbers and true or false values?

With Detect types selected, plain numbers such as 42 or 3.5 become JSON numbers, and the words true and false become booleans. Values with leading zeros, such as 00123, and very long numbers stay as text. With Keep as text selected, every value stays as text.

Is there a size limit?

Files up to 5 MB can be added. For pasted text, keep it to a similar size, because the work happens on your device.

Share this article