本文へスキップ

Convert XML to JSON

Turn an XML document into JSON with attributes as @keys, repeated elements as arrays and numbers typed, parsed by your browser's own XML parser on your device.

Convert to
Drop an XML fileXML up to 100 MB · JSON, CSV, XLSX, XLS, ODS up to 500 MB
ファイルを選択端末上で処理 — アップロードされません
ブラウザで動作・アップロード不要しくみ

XML to JSONの使い方

  1. 1

    Paste or drop the XML

    A .xml file, an RSS or Atom feed, a SOAP response or any XML text; the encoding in its declaration is respected.

  2. 2

    Set the JSON shape

    Attributes as @keys, plain keys or none; arrays only for repeated elements or everywhere; numbers typed or kept as text.

  3. 3

    Copy the JSON

    Pretty-printed or compact — copy it to the clipboard or download the .json file.

制限と Pro

XML files up to 100 MB, pasted XML of any size your browser can hold.

XML to JSON について

XML to JSON is for the moment an API, a government portal or an old integration hands you XML and your code wants JSON. The document's root element becomes the single top-level key, each child element becomes a property, and an element that occurs several times under one parent becomes an array, in document order.

Attributes need a decision because JSON has no such thing. The default writes them as keys starting with @ — <price currency="UZS">125000</price> becomes {"@currency": "UZS", "#text": 125000} — which keeps attributes and child elements apart and lets the JSON be turned back into the same XML. Plain keys give shorter objects; leaving attributes out suits documents that use them only for housekeeping.

Values: with type detection on, 42 and 3.5 become JSON numbers and true/false become booleans, but anything that would change if read as a number stays a string — postcodes and account numbers with leading zeros, numbers longer than 15 digits. Empty elements become empty strings.

Namespaces are kept as written (dc:title), or the prefixes can be dropped for cleaner keys, which also removes the xmlns declarations. "Always use arrays" gives every child element the same array shape, convenient when some records have one author and others have three.

Not carried over: comments, processing instructions and the DOCTYPE; text that is mixed with inline tags, as in XHTML paragraphs, is joined into a single string.

プライバシー

The XML is parsed in a background worker of this page with no network request; no DTD or external entity is fetched and the document never leaves your device.

XML to JSON:よくある質問

What does #text mean in the JSON?
When an element has attributes or child elements and also text of its own, the text needs a key of its own; #text is the common convention. <title lang="en">Guide</title> becomes {"@lang": "en", "#text": "Guide"}. An element with nothing but text becomes a plain value instead, so <title>Guide</title> is simply "title": "Guide".
Are numbers converted or left as strings?
With “Detect numbers and true/false” on, values that are clearly numbers or booleans get JSON types. Values with leading zeros, such as 007 or a postcode, and numbers with more than 15 digits stay strings, because turning them into numbers would change them. Switch detection off to keep every value exactly as text.
How are namespaces such as soap: or dc: handled?
Prefixes stay part of the key by default, so dc:title is the key "dc:title" and xmlns declarations appear as @xmlns attributes. Turn on “Drop namespace prefixes” to get title and to leave the declarations out. Two different namespaces using the same local name would then share a key, so keep prefixes when that matters.
Can I convert the JSON back to XML afterwards?
Yes. Switch the target to XML on the JSON to XML page: keys that start with @ become attributes, #text becomes the element's text and arrays become repeated elements. Element order inside a parent may change when different child names were interleaved, and comments are gone, but the data itself survives the round trip.
Why do I get an error instead of JSON?
The XML isn't well-formed, and the message shows the line and column of the first problem. Common causes are an & that should be &amp;, a tag closed in the wrong order, an attribute value without quotes, or HTML entities such as &nbsp; that XML doesn't define. Fix that spot and paste again.

このツールでできるほかのこと