jsonecho

XML to JSON

Paste XML and get structured JSON back. Attributes, repeated tags and mixed text are all handled.

Loading the tool...

How to use XML to JSON

  1. Paste your XML or upload a .xml file.
  2. Decide whether to convert numbers and booleans.
  3. Copy the JSON or switch to Tree view to explore it.

About XML to JSON

XML and JSON do not map one to one, so it helps to know the rules. Attributes become keys that start with @_, for example id="7" turns into "@_id": 7. When an element has both attributes and text, the text goes into a #text key. Elements that repeat become an array, and a tag that appears once stays a plain value.

By default numbers and booleans are detected, so <qty>2</qty> becomes the number 2. Values with leading zeros, such as postal codes or phone numbers, stay strings. Turn the option off if you want every value as text.

Frequently asked questions

Why is one element an object and another an array?

A tag that appears once becomes a single value, and the same tag appearing twice becomes an array. If your code expects an array every time, wrap single values in a list when you read them.

What happens to XML comments?

They are ignored. JSON has no equivalent.

How are namespaces treated?

Prefixes stay part of the name, so <soap:Body> becomes the key soap:Body.

My XML is invalid, what now?

You get the line, the column and a message such as "Expected closing tag 'b'". Fix that spot and the conversion runs again by itself.

Can I convert JSON back to XML?

Yes, with the JSON to XML tool. Use the same @_ and #text conventions to keep attributes.

More in Converters

All tools →