DataSwitch Pro Private, in-browser data converter

JSON to TOML Converter

Turn JSON objects into readable TOML configuration with tables and arrays of tables.

Copied to clipboard!
Rows
0
Columns
0
Delimiter
—
Input Size
0 B
Output Size
0 B
Speed
0 ms

How to convert JSON to TOML

Updated · 3 min read

TOML is a configuration format designed to be obvious to read: Python's pyproject.toml, Rust's Cargo.toml, Hugo, Netlify and many CLI tools use it. This converter maps JSON objects to TOML tables and arrays of objects to arrays of tables, following the TOML 1.0 specification.

  1. Paste a JSON object or drop a .json file.
  2. Nested objects become [tables], arrays of objects become [[arrays of tables]].
  3. Read any notice: TOML has no null, so null values are left out.
  4. Copy the TOML or download a .toml file.

Example

JSON input

{
  "title": "My site",
  "server": { "host": "0.0.0.0", "port": 8080, "tls": false },
  "plugins": [
    { "name": "sitemap", "enabled": true },
    { "name": "analytics", "enabled": false }
  ]
}

TOML output

title = "My site"

[server]
host = "0.0.0.0"
port = 8080
tls = false

[[plugins]]
name = "sitemap"
enabled = true

[[plugins]]
name = "analytics"
enabled = false

The server object becomes a [server] table and the plugins array of objects becomes two [[plugins]] entries — the idiomatic way to write lists of records in TOML.

Your data stays on your device. The conversion runs in JavaScript inside this tab — files and pasted text are never uploaded to DataSwitch Pro.

How JSON maps to TOML

Where TOML is used

Python packaging (pyproject.toml for pip, uv, Poetry, Hatch, Ruff and Black), Rust (Cargo.toml), Hugo site configuration, Netlify (netlify.toml), Deno, Gitea, InfluxDB/Telegraf and many more. It is a good choice whenever humans edit configuration by hand.

Dates and comments

TOML has native date and time types, but JSON stores dates as strings, so they remain quoted strings in the output. Add # comments to the TOML afterwards — one of its advantages over JSON.

Real-world examples

Create a pyproject.toml section

Python packaging uses TOML. Writing metadata as JSON first — or reusing it from another tool — and converting avoids TOML quoting mistakes.

JSON

{
  "project": {
    "name": "dataswitch-demo",
    "version": "0.3.1",
    "requires-python": ">=3.10",
    "dependencies": ["pandas>=2.2", "openpyxl"]
  }
}

TOML

[project]
name = "dataswitch-demo"
version = "0.3.1"
requires-python = ">=3.10"
dependencies = [ "pandas>=2.2", "openpyxl" ]

Configure a Rust or Hugo project

Cargo.toml and Hugo's config use nested tables. Nested JSON objects become [section.subsection] headers.

JSON

{
  "package": { "name": "csv-tool", "version": "1.0.0", "edition": "2021" },
  "dependencies": { "serde": { "version": "1.0", "features": ["derive"] } }
}

TOML

[package]
name = "csv-tool"
version = "1.0.0"
edition = "2021"

[dependencies.serde]
version = "1.0"
features = [ "derive" ]

Common errors and how to fix them

Some keys are missing from the TOML

TOML has no null value, so keys whose value is null are left out and a warning tells you how many. Replace null with an empty string or a default if the key must exist.

A top-level array became [[records]]

A TOML document is always a table, so a top-level JSON array is placed under [[records]]. Wrap it yourself — {"items": [...]} — to choose the name.

Keys appear in quotes

Keys containing dots, spaces or other special characters must be quoted in TOML, e.g. "requires-python" is fine but "a.b" needs quotes.

Mixed-type arrays

Older TOML parsers reject arrays like [1, "a"]. TOML 1.0 allows them, but keep arrays to one type for maximum compatibility.

Related guides

Convert JSON to TOML in code

For one-off files the tool above is quickest. To automate the same task in a script or pipeline, these snippets are a good starting point.

Python (tomli-w)

import json
import tomli_w  # pip install tomli-w

with open("config.json", encoding="utf-8") as f:
    data = json.load(f)

with open("config.toml", "wb") as f:
    tomli_w.dump(data, f)

Node.js (smol-toml)

import { stringify } from "smol-toml";  // npm install smol-toml
const toml = stringify(JSON.parse(text));

Frequently asked questions

Why were some values removed?

TOML has no null type, so keys whose value is null are left out. A notice tells you how many were omitted.

Can I convert a JSON array?

Yes, but TOML requires a table at the top level, so the array is placed under [[records]]. Wrap your array in an object to choose the name yourself.

Is the output valid for pyproject.toml?

The output is valid TOML 1.0. Whether a key is valid for pyproject.toml depends on the tools that read it.

Can I convert YAML to TOML?

Yes. Choose YAML as the source and TOML as the target.

Is my config uploaded?

No. It is converted in your browser.

Related converters