Open tools · 0

About

XML to JSON

Paste XML, or drop an .xml, .svg, .rss or .plist file, and the JSON is written as you type. The root element becomes the top key, attributes become keys starting with @, text beside them goes under #text, and elements that repeat become an array. Every value arrives as a string, because XML holds nothing but text.

What it does

  • An element with attributes keeps them: <price currency="EUR">9.99</price> becomes {"price": {"@currency": "EUR", "#text": "9.99"}}.
  • Namespace prefixes stay in the names, as "dc:creator", and each xmlns declaration becomes an @xmlns key, so the JSON converts back.
  • CDATA sections become ordinary text, and XML’s five entities and numeric ones such as &#233; are decoded.
  • An empty element such as <br/> becomes "", and the text of an element with no children keeps its spaces.
  • The comments are counted in the summary and left out, since JSON cannot hold them.
  • A tag left open or closed under the wrong name is placed by line and column, and a second root element is refused.

How to use it

  1. Paste the XML, or drop the file on the window.
  2. Choose 2, 3 or 4 spaces, or One line.
  3. Read the notes: each says where the JSON could not keep the XML as it was.
  4. Copy the JSON, or download it under the XML file’s name.

What it does not do

  • Numbers and booleans guessed from text: <n>007</n> could be a code, so every value stays the string it was.
  • Entities a DOCTYPE defines: only XML’s own five and numeric references are decoded, so &copy; and the like stay as written.
  • The place of text among elements: in <p>Hello <b>world</b></p> the text is gathered under #text, and the notes say so.

Questions

Why is one value an array and another not?

An element that appears once becomes a value, and one that repeats becomes an array: one <item> gives "item": {...}, two give "item": [...]. Code reading the JSON should accept both, or wrap a single value in an array itself.

Why are my numbers in quotes?

XML stores everything as text, and values such as 007, 1.10 or +44 20 lose something as numbers. Each value stays the string it was; the notes say so once, and your code can turn the fields it knows to be numbers.

Can I turn the JSON back into XML?

Yes, press Swap. Attributes, text, repeated elements and namespace prefixes go back where they were. What changes is the order: elements of one name that had others between them come back side by side.

Does it read SVG and RSS?

Yes: .svg, .rss, .atom, .xsd, .xsl and .plist files are taken as XML when dropped. A plist reads poorly, though: its keys and values are grouped by tag name, so each key is no longer beside its value.

Everything here runs in your browser. Nothing you type, paste or open is uploaded, and there is no account and no queue. How that works.

Often used with

More in Converters

  • Unit Converter: Convert length, weight, temperature, volume, area, speed, data size and nine more quantities, both ways, with the formula.
  • Base64 Encode & Decode: Encode text or files to Base64 and decode it back: URL-safe, MIME line breaks, data URIs, and images you can preview.

All toolsAbout utilbrewPrivacy