<!-- TOML vs YAML vs JSON for Config Files -->
<!-- Canonical: https://dataswitchpro.com/guides/toml-vs-yaml-vs-json/ -->
> TOML, YAML and JSON compared for configuration: comments, types, nesting and pitfalls, with examples from pyproject.toml, Cargo and Docker Compose.

[Home](https://dataswitchpro.com/) › [Guides](https://dataswitchpro.com/guides/)

# TOML vs YAML vs JSON for Configuration Files

By the DataSwitch Pro team · November 20, 2026 · 4 min read

## Quick answer

TOML is explicit and unambiguous — every string is quoted, types are clear, comments are allowed — which makes it ideal for flat or moderately nested settings such as `pyproject.toml` and `Cargo.toml`. YAML is the most compact and readable for deeply nested structures (Kubernetes, Docker Compose, CI pipelines) but has indentation and implicit-typing pitfalls. JSON is strict and universal but has no comments, so it suits files written by programs, such as `package.json` lock data and API payloads, better than hand-edited config.

Most projects end up with all three: a `package.json`, a `docker-compose.yml` and a `pyproject.toml` or `Cargo.toml`. Each format was designed with different trade-offs, and knowing them helps you pick the right one for a new file — and avoid the classic mistakes in each.

## The same settings in three formats

### TOML

```
# Application settings
[server]
host = "0.0.0.0"
port = 8080

[database]
url = "postgres://localhost/app"
pool_size = 10

[[workers]]
name = "emails"
threads = 2
```

### YAML

```
# Application settings
server:
  host: 0.0.0.0
  port: 8080
database:
  url: postgres://localhost/app
  pool_size: 10
workers:
  - name: emails
    threads: 2
```

### JSON

```
{
  "server": { "host": "0.0.0.0", "port": 8080 },
  "database": { "url": "postgres://localhost/app", "pool_size": 10 },
  "workers": [ { "name": "emails", "threads": 2 } ]
}
```

## Comparison

- **Comments**: TOML and YAML yes (`#`); JSON no.
- **Strings**: TOML and JSON always quote strings; YAML usually does not, which is convenient but leads to values being read as numbers or booleans by accident.
- **Types**: TOML has strings, integers, floats, booleans, arrays, tables and native date-times — but *no null*. JSON has null but no dates. YAML infers types, including dates in some parsers.
- **Nesting**: YAML and JSON nest naturally. TOML uses section headers such as `[server]` and `[server.tls]`; deep nesting means long, repeated header paths.
- **Lists of objects**: TOML uses *arrays of tables* (`[[workers]]`), which surprise newcomers; YAML uses `-`  items; JSON uses arrays.
- **Whitespace**: only YAML is indentation-sensitive. TOML and JSON ignore indentation.
- **Parser complexity**: JSON is tiny and consistent everywhere; TOML is small and well specified (version 1.0); YAML is large, with behaviour that differs between YAML 1.1 and 1.2 parsers.

## Where each one is the norm

- **TOML**: Python packaging (`pyproject.toml`), Rust (`Cargo.toml`), Hugo, Netlify, many CLI tools.
- **YAML**: Kubernetes, Docker Compose, GitHub Actions, GitLab CI, Ansible, OpenAPI.
- **JSON**: `package.json`, `tsconfig.json` (which unofficially accepts comments), VS Code settings, API payloads.

When a tool has a convention, follow it. The choice only really matters for new files you design yourself.

## How to choose for a new file

1. **Mostly written by programs?** Use JSON.
2. **Edited by people, mostly flat sections of settings?** Use TOML: it is hard to get wrong and easy to read.
3. **Edited by people, deeply nested or long lists of structured items?** Use YAML, with quoting rules agreed in the team and a linter in CI.

## Common pitfalls

- **TOML**: forgetting quotes around strings (`name = app` is invalid), defining the same table twice, needing a value of null (omit the key instead), and Windows paths in double quotes — use single quotes: `path = 'C:\data'`.
- **YAML**: tabs, uneven indentation, `no` or `on` turning into booleans, `1.10` turning into 1.1. See [common YAML errors](https://dataswitchpro.com/guides/fix-yaml-errors/).
- **JSON**: trailing commas and comments. See [common JSON errors](https://dataswitchpro.com/guides/fix-invalid-json-errors/).

## Converting between them

Moving a configuration from one format to another is mostly mechanical: [JSON to TOML](https://dataswitchpro.com/json-to-toml/) turns nested objects into `[section]` tables, and [TOML to JSON](https://dataswitchpro.com/toml-to-json/) shows exactly how a TOML file is structured — useful when arrays of tables are confusing. Watch for the differences above: null values have no TOML equivalent, comments are lost when converting to JSON, and dates become plain strings in JSON. For a closer look at the other pair, read [YAML vs JSON](https://dataswitchpro.com/guides/yaml-vs-json/).

**Try it on your own file.** Free, private, and processed in your browser.

[JSON to TOML](https://dataswitchpro.com/json-to-toml/)[TOML to JSON](https://dataswitchpro.com/toml-to-json/)[JSON to YAML](https://dataswitchpro.com/json-to-yaml/)[YAML to JSON](https://dataswitchpro.com/yaml-to-json/)

## Frequently asked questions

### Does TOML support null?

No. Omit the key, or use an empty string or another sentinel value that your program understands.

### Is TOML better than YAML?

For simple, flat configuration, TOML is usually safer because it has no indentation or implicit-typing surprises. For deep nesting, YAML is more compact.

### Can I put comments in package.json?

No. npm reads strict JSON. Some tools accept a `"//"` key as a workaround, but it is just data.

### Which format does pyproject.toml use?

TOML, as standardised by the Python packaging specifications (PEP 518 and PEP 621).

## More guides

- [YAML vs JSON: Differences, Pitfalls and When to Use Each](https://dataswitchpro.com/guides/yaml-vs-json/)
- [Common YAML Errors and How to Fix Them](https://dataswitchpro.com/guides/fix-yaml-errors/)
- [Invalid JSON? 10 Common Syntax Errors and How to Fix Them](https://dataswitchpro.com/guides/fix-invalid-json-errors/)
- [Why Your CSV Opens in One Column in Excel (and How to Fix It)](https://dataswitchpro.com/guides/csv-opens-in-one-column-excel/)
