Data converter

Convert between JSON, YAML, TOML, XML, CSV and .env.

loading Data converter
About this tool

What is a data format converter?

Configuration and data travel in many text formats, and the same information has to move between them all the time. A Kubernetes manifest is YAML but your script wants JSON; a Cargo or Python project file is TOML; an older Java service reads .properties; a spreadsheet exports CSV; a legacy API returns XML; a deploy pipeline wants .env variables. Rewriting by hand is where indentation errors and lost quotes creep in.

This data converter reads JSON, YAML, TOML, XML, CSV, .env and Java Properties and writes any of them, in both directions. You can leave the input format on automatic detection or choose it yourself, and you pick the output format. It formats the result with the indentation you choose, can sort keys, minify JSON and XML, and keeps big integers exact: a number such as 12345678901234567890 is not rounded the way a normal JavaScript number would be.

The conversion happens in your browser and nothing is sent to a server, which matters because the data you paste is often a config with hostnames, keys or customer records.

How to convert between JSON, YAML, TOML, XML and CSV

  1. Paste your data in Input. The tool opens with a small JSON example so you can see a result at once.
  2. Leave From on Detect automatically, or choose the format. A line such as "Detected: YAML" tells you what was recognised.
  3. Choose the target in To: JSON, YAML, TOML, XML, CSV, .env or Properties. The output updates as you type.
  4. Set the Indent (2 spaces, 4 spaces or a tab) for JSON, YAML and XML. Turn on Sort keys to order the keys alphabetically at every level, or Minify to get JSON or XML on one line.
  5. For XML and CSV input, Turn text like 12 and true into numbers and booleans is on by default. Turn it off to keep every value as text.
  6. Use the swap button to turn the output into the new input and reverse the direction, then Copy the result or Download it as a file with the right extension.

If the input has an error, the tool says which format it was reading and shows the line and column, with the offending line, and keeps updating as you fix it. Specific pages exist for the common pairs, such as JSON to YAML and TOML to JSON; this one covers every combination.

Examples of data conversion

JSON to YAML and TOML

Input JSON:

{
  "name": "toolbox-dev",
  "ids": [9007199254740993, 12345678901234567890],
  "server": { "host": "localhost", "port": 8080, "debug": true },
  "tags": ["dev", "tools"]
}

YAML output, with both large numbers intact:

name: toolbox-dev
ids:
  - 9007199254740993
  - 12345678901234567890
server:
  host: localhost
  port: 8080
  debug: true
tags:
  - dev
  - tools

TOML output puts the table last:

name = "toolbox-dev"
ids = [ 9007199254740993, 12345678901234567890 ]
tags = [ "dev", "tools" ]

[server]
host = "localhost"
port = 8080
debug = true

CSV to JSON

name,age,city
Ana,31,Lisboa
Bruno,28,"São Paulo, SP"

becomes a list of objects. age is a number, and the quoted comma stays inside "São Paulo, SP". The delimiter can be a comma, semicolon, tab or pipe: nome;idade is detected too.

JSON to CSV

[{"id":1,"name":"Ana","tags":["a","b"]},{"id":2,"name":"Bruno, Jr."}] gives:

id,name,tags
1,Ana,"[""a"",""b""]"
2,"Bruno, Jr.",

Columns are the union of all keys, missing values stay empty and nested values are written as JSON text.

.env to JSON

DB_PORT=5432 and export DEBUG=true become strings, "5432" and "true", because an .env file has no types. The export prefix is accepted.

XML attributes

<server host="localhost" port="8080"/> becomes an object with "@host": "localhost" and "@port": 8080: attributes are prefixed with @, and repeated elements such as two <tag> become an array.

JSON to Properties and .env

Nested keys are flattened: server.host=localhost and ids[0]=9007199254740993 in Properties, SERVER_HOST=localhost and IDS_0=9007199254740993 in .env.

Common errors and how to fix them

  • Error in the JSON input, at line 1, column 8. A trailing comma, as in {"a":1,}, a missing quote or a missing bracket. Fix the highlighted spot; the output updates while you type.
  • TOML has no null value (at a). TOML cannot store null. Remove the key or give it a value; JSON, YAML and the others keep null.
  • TOML needs an object at the top level. A TOML file is a set of key = value pairs, so a JSON list such as [1,2] cannot be converted.
  • This row has 3 columns and the header has 2. In CSV every row must match the header. Add or remove a field, and quote values that contain the delimiter.
  • The format of the input was not recognised. Plain text such as hello world is none of the seven formats. Choose the format in From.
  • CSV needs a list of objects, one row per object. A JSON value that is not a list of objects cannot become a table. Wrap it, or choose another output.
  • "1bad" cannot be an XML element name. XML names must start with a letter and use only letters, digits, underscore, hyphen or dot.

Frequently asked questions

How do I convert JSON to YAML?

Paste the JSON, choose YAML in To and copy. Comments are not kept in either direction, because JSON has none and a parsed document does not store them. To check the JSON first, use the JSON formatter.

Does converting change my values?

Types are preserved between JSON, YAML and TOML, and large integers are exact. CSV, .env, XML and Properties carry text, so numbers read from them depend on the type inference switch. Compare two versions with JSON diff.

Which formats can be read and written?

JSON, YAML, TOML, XML, CSV, .env and Java Properties, each as input and as output. Every pair is possible, subject to the format's limits, such as TOML not having null.

Is my data uploaded?

No. The conversion runs in your browser, so configuration with secrets stays on your computer.

How do I convert XML to JSON?

Choose XML in From and JSON in To. Attributes become keys that start with @, and repeated elements become arrays, as in the example above.

How to convert data formats in code

Python

json and csv ship with Python, and tomllib (3.11 and later) reads TOML.

import csv, io, json, tomllib

tomllib.loads('name = "app"\n[limits]\ncpu = "500m"\n')   # {'name': 'app', 'limits': {'cpu': '500m'}}
rows = list(csv.DictReader(io.StringIO('name,age\nAna,31')))
json.dumps(rows, ensure_ascii=False)                       # '[{"name": "Ana", "age": "31"}]'

JavaScript

const data = JSON.parse('{"name":"app","replicas":3}');
JSON.stringify(data, null, 2);        // formatted JSON
// YAML needs a library, for example: import YAML from 'yaml'; YAML.stringify(data)

Bash

yq converts between formats and jq shapes JSON.

printf 'name: app\nreplicas: 3\n' | yq -o=json '.'
printf 'name = "app"\n[limits]\ncpu = "500m"\n' | yq -p=toml -o=json
echo '[{"name":"Ana","age":31}]' | jq -r '(.[0]|keys_unsorted) as $k | $k, (.[]|[.[$k[]]]) | @csv'
Report a problem