Skip to content
HandyKit

How to Convert JSON to CSV, YAML or XML

· 2 min read

You have JSON from an API or an export, and you need it as a spreadsheet, a config file or XML. Each of those formats handles nesting, arrays and empty values in its own way, so it helps to know what to expect before you convert.

The JSON Converter turns JSON into CSV, YAML or XML. It converts from JSON only; it does not read CSV, YAML or XML back into JSON.

The example input

The examples below all use this input: two people, each with a nested address and a list of tags. The second has a null email and an empty list.

[
  { "name": "Ada", "email": "ada@example.com", "address": { "city": "London" }, "tags": ["admin", "editor"] },
  { "name": "Grace", "email": null, "address": { "city": "New York" }, "tags": [] }
]

Converting to CSV

Choose CSV and the converter gives:

name,email,address.city,tags
Ada,ada@example.com,London,"[""admin"",""editor""]"
Grace,,New York,[]

The output follows four rules:

  • An array of objects becomes one row per object, with the keys as column names.
  • Nested objects become dotted columns: the address gives a column named address.city.
  • An array inside an object is written as JSON text in a single cell. The cell is quoted as RFC 4180 requires, with each quote doubled, which is why Ada's tags look the way they do.
  • A null value becomes an empty cell, so Grace's row has two commas side by side.

A spreadsheet will not split the tags cell into separate values, because it holds JSON text.

Opening the CSV in Excel

Excel in some locales expects semicolons between values rather than commas, and then puts everything in one column. Either choose the semicolon separator in the converter and convert again, or import the file with Data > From Text/CSV and pick the separator there. The converter also offers tab as a separator.

Converting to YAML

Choose YAML and the same input gives:

- name: Ada
  email: ada@example.com
  address:
    city: London
  tags:
    - admin
    - editor
- name: Grace
  email: null
  address:
    city: New York
  tags: []

Each object becomes a list item, the address becomes an indented block, and each tag gets its own dash. In YAML the indentation carries the structure, so keep the spacing exactly as it is when you copy it into a config file.

How YAML quoting works

The converter leaves a string unquoted only when YAML would read it back as the same string. Values such as yes, on, null, 1.0, a: b and the empty string are written in double quotes, because otherwise a parser could read them as a boolean, null, a number, a mapping or nothing at all.

This avoids the "Norway problem", where YAML 1.1 parsers turn the country code NO into false.

Converting to XML

Choose XML and the keys become element names. Characters that are not allowed in an element name become underscores, so a key such as first name becomes first_name. An array repeats its element once for each item.

Large numbers and errors

Numbers are copied exactly as written, so 12345678901234567890 stays unchanged. JSON.parse in JavaScript would round it.

If your JSON has an error, fix it first: the JSON Formatter shows where it is. The converter runs in your browser, so nothing is uploaded.

Try it

Paste your JSON into the JSON Converter, choose CSV, YAML or XML, and download the result.

Tools in this guide

  • JSON Converter

    Turn JSON into CSV for spreadsheets, YAML for configuration or XML for older systems. Nested data is handled sensibly and big numbers are never rounded.

  • JSON Formatter

    Paste or open JSON to pretty-print it, explore it as a tree, or repair almost-JSON. Errors are pinpointed by line and column, with a suggested fix.

  • · 2 min read

    Minify JSON: What It Does and When to Use It

    What minifying JSON removes, what it never changes, when it is worth doing and when it is not, and why sorting keys gives stable output you can compare or hash.

  • · 2 min read

    How to Compare Two JSON Files

    Find what changed between two JSON documents, ignoring key order and formatting. A worked example, how to read JSONPath, and how arrays and numbers compare.

  • · 4 min read

    Common JSON Errors and How to Fix Them

    Trailing commas, single quotes, comments, True and None: the JSON syntax errors developers hit most often, what each error message means, and how to fix it.