JSON to XML Converter

Paste JSON and get XML, with a few simple rules for attributes, text and repeated elements.

Free tools that run in your browser. Nothing you type, open or create is uploaded to NerdBible or anyone else.

YAML

Converted in your browser with js-yaml (MIT licence). YAML comments, anchors and custom tags have no JSON equivalent, so comments are dropped and anchors are written out in full. A YAML file with several documents separated by --- becomes a JSON array.

How to use it

  1. Pick the format: YAML, XML, CSV, TSV or TOON. Then pick the direction, such as JSON to YAML or TOON to JSON.
  2. Paste your data. The result updates as you type, and an error shows its line and column.
  3. Set the options: indent and key order for YAML, the declaration and value types for XML, the delimiter, header row and quoting for CSV and TSV, or the delimiter and indent for TOON.
  4. Copy or download the result, or press Swap to convert it back.

Questions

How do I make an XML attribute from JSON?

Start the key with @. For example "@id": "b1" inside a book object gives <book id="b1">.

How are JSON arrays converted to XML?

Each item becomes its own element with the array's key as the name, so "book": [ ... ] produces one book element per item.

Why is my XML wrapped in a root element?

XML must have exactly one top-level element. When the JSON has more than one top-level key, they are placed inside a root element.

About this tool

The mapping rules

JSON and XML shape data differently, so a converter needs rules. These are the common conventions used by many libraries.

  • Keys become elements. A key named title with the value Dune becomes <title>Dune</title>.
  • @ keys become attributes. A key such as @id is written as id="b1" on its parent element.
  • #text is the element text when an element also has attributes or children.
  • Arrays repeat the element. A list under book becomes one <book> element per item.
  • One root. XML allows a single top-level element, so JSON with several top-level keys is wrapped in a root element.

Output options

Choose 2 or 4 space indentation, or none for the smallest file, and whether to start with an XML declaration. Characters such as & and < in values are escaped so the result is well-formed. Keys that are not valid XML names, such as ones with spaces or a leading digit, are adjusted: other characters become underscores, and an underscore is added in front where needed.

The XML tab also converts the other way, and nothing you paste leaves your browser.

Related tools