More
More
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.
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.
The rules: a key starting with @ is an attribute, the key #text holds an element's text next to attributes or children, and an array becomes the same element repeated. When there is more than one top-level key, the XML is wrapped in a root element. Comments, processing instructions and the DOCTYPE are skipped when reading XML, and entities other than the five standard ones are not expanded.
Nested objects are flattened into dot keys (address.zip) and arrays into numbered keys (tags.0, tags.1), and the reverse when converting back. Columns appear in the order they are first seen. CSV follows RFC 4180: fields with the delimiter, a quote or a line break are wrapped in double quotes. TSV is the same with a tab between fields.
TOON (Token-Oriented Object Notation) is a compact way to write JSON for large language model prompts: objects use indentation instead of braces, and a list of objects that share the same keys is written once as a header, such as hikes[3]{id,name,km,sunny}:, followed by one row per item. This converter follows the public TOON specification for objects, inline lists, tabular arrays, list items, quoting and the comma, tab and pipe delimiters.
How to use it
- Pick the format: YAML, XML, CSV, TSV or TOON. Then pick the direction, such as JSON to YAML or TOON to JSON.
- Paste your data. The result updates as you type, and an error shows its line and column.
- 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.
- 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
- JSON Formatter & ValidatorPretty-print, minify and validate JSON.
- Code Formatter & MinifierFormat or minify HTML, CSS, JavaScript, SQL, XML, YAML and GraphQL, and check XML.
- HTML Entities List & EncoderEvery named HTML entity with its codes, plus an encoder and decoder.
- Escape, Encode & DecodeEscape and unescape text for JSON, JavaScript, HTML entities, XML, SQL, CSV, regex and URLs.