What changes when data is converted between JSON, CSV, YAML and XML?
The four formats model data differently: JSON and YAML carry nesting and types, CSV is a flat table of strings, and XML distinguishes elements from attributes. A converter therefore has to make choices — how to flatten nested objects into columns, how to type "42" and "true", where attributes go — and the right choice depends on what the receiving system expects.
How to use JSON to XML
- Paste the JSON document (use @_name keys for attributes if needed).
- Set the root and item element names and the formatting style.
- Copy or download the XML.
JSON to XML features
- Configurable root element and array item element names
- @_ prefixed keys become attributes, "#text" becomes element text
- Arrays repeat elements; top-level arrays are wrapped automatically
- Invalid element names are sanitised so the output is always well-formed
- Special characters escaped as XML entities
- Pretty-printed or compact output, optional XML declaration
JSON to XML example
Object with attributes and a list
Input:
{"order":{"@_id":"1001","items":[{"sku":"KB-100"},{"sku":"MS-220"}]}}Output:
<?xml version="1.0" encoding="UTF-8"?>
<order id="1001">
<items>
<sku>KB-100</sku>
</items>
<items>
<sku>MS-220</sku>
</items>
</order>Frequently asked questions about JSON to XML
How do I produce XML attributes?
Prefix a key with @_ (for example "@_id": "42") and it becomes an attribute of the parent element. Use "#text" for the text content of an element that also has attributes.
How are arrays converted?
An array under a key repeats that element once per item (<tag>a</tag><tag>b</tag>). A top-level array is wrapped in the root element with one item element per entry — both names are configurable.
What if a key is not a valid XML name?
Invalid characters are replaced by underscores and names that start with a digit get a leading underscore, so the output is always well-formed.
Are special characters escaped?
Yes. &, <, >, quotes and apostrophes in values and attributes are escaped as XML entities.
References
- RFC 8259: The JavaScript Object Notation (JSON) Data Interchange FormatThe JSON grammar: objects, arrays, strings, numbers, the three literals, and UTF-8 as the interchange encoding.
- RFC 4180: Common Format and MIME Type for Comma-Separated Values (CSV) FilesThe commonly implemented CSV rules: comma separators, CRLF line ends, quoting of fields that contain commas, quotes or line breaks.
- YAML Ain't Markup Language (YAML™) version 1.2.2The YAML 1.2 data model and syntax, and its relationship to JSON (every JSON document is valid YAML 1.2).