Nouplo

XML to JSON

With the rules stated, so nothing surprises you.

Examples temporarily replace the input and settings. You can restore your previous work.

0 characters
Output
Paste or type above to see the result here.

Your files stay on your device

This tool runs entirely in your browser. What you paste is processed on your device and is never sent to a server, so it is safe to use with tokens, keys and unpublished text.

Example

Example: a podcast RSS feed turned into JSON for a web app

A developer wants a podcast’s episode list as JSON. The feed is an rss element with version="2.0", holding a channel with a title and two item elements. Each item has a title and an episode number; the first also has an empty enclosure element whose url, length and type are attributes. Settings: keep the root element, 2 spaces.

  1. version="2.0" becomes "@version": "2.0". Attributes get an @ in front, and so do the enclosure’s url, length and type.
  2. item appears twice inside the same channel, so "item" becomes an array of two objects.
  3. The escaped ampersand in the title “Sourdough & Patience” is decoded back to &.
  4. The episode number 012 stays the string "012": nothing is turned into a number, so the leading zero survives.
In the XML In the JSON
rss with version="2.0" "rss": { "@version": "2.0", … }
enclosure with url, length="48213760" and type="audio/mpeg" "enclosure": { "@url": "https://example.com/ep12.mp3", "@length": "48213760", "@type": "audio/mpeg" }
two item elements in one channel "item": [ { … }, { … } ]
title “Episode 12: Sourdough & Patience”, the & escaped "title": "Episode 12: Sourdough & Patience"
episode 012 "episode": "012"

486 characters of JSON with "rss" as the outer key; with “Drop it” the root goes and the JSON, now 433 characters, starts at "@version". A feed with a single episode gives "item" as one object, not an array, so code that reads it should accept both.

How it works

  1. Paste the XML.
  2. Choose whether to keep the root element as the outermost key.
  3. Read the JSON. Attributes appear as @name and any loose text as #text.
  4. Copy it.

Frequently asked questions

What happens to attributes?
They become keys prefixed with @, so <a id="1">text</a> becomes {"@id": "1", "#text": "text"}. There is no way to express an attribute in JSON, so every converter invents a convention; this uses the one most of them settled on.
Why did one element become an array and another not?
Because XML has no way to say “this is a list of one”. A name appearing twice inside the same parent becomes an array; appearing once, it stays a single value. If your consumer always expects an array, it has to cope with both — that ambiguity is in the XML, not in the conversion.
Are the numbers converted?
No. Everything comes out as a string, because XML has no types and guessing produces the classic bug where a version number like 1.10 becomes 1.1 or a leading zero is lost from an identifier.
Does it decode entities like &amp;?
Yes. &amp;, &lt;, &gt;, &quot; and &apos;, and numeric ones such as &#233;, come out as the characters themselves, and a CDATA section comes through as its text, exactly as written inside it. Comments and processing instructions are dropped, because they have nowhere to go in JSON.
What happens to namespaced tags like itunes:episode?
The prefix stays part of the name, so <itunes:episode> becomes the key "itunes:episode", and an xmlns:itunes declaration on the root comes through as the attribute "@xmlns:itunes".
Should I keep or drop the root element?
Keep it and the JSON starts with the root’s name, {"rss": {…}}, which says what the document was. Drop it and you get the root’s content directly, one level shallower, which is handier when you already know what you loaded.
Is anything sent to a server?
No. It runs in your browser, so what you type stays on your computer.

Related tools