Configuration lives in text files, and three formats dominate: JSON, YAML and TOML — with INI and .env files still everywhere. Each has a reason to exist and a set of traps. This guide compares them with the same example, explains when each is the right choice, and covers the conversion pitfalls that break deployments.

The same settings in each format

JSON

{
  "app": { "name": "shop", "port": 8080, "debug": false },
  "db": { "host": "localhost", "replicas": ["r1", "r2"] }
}

YAML

app:
  name: shop
  port: 8080
  debug: false   # comments are allowed
db:
  host: localhost
  replicas:
    - r1
    - r2

TOML

[app]
name = "shop"
port = 8080
debug = false

[db]
host = "localhost"
replicas = ["r1", "r2"]

.env

APP_NAME=shop
APP_PORT=8080
DB_HOST=localhost

JSON: strict and universal

Every language parses JSON, and its strictness means a file either parses or it does not. That makes it ideal for machine-written configuration and data exchange. The downsides for humans: no comments, lots of quotes and braces, and trailing commas are errors (see common JSON errors). Used by package.json, tsconfig.json (with comments allowed as an extension) and most APIs.

YAML: readable, with sharp edges

YAML uses indentation instead of brackets and allows comments, which makes it pleasant to read. It is the format of Kubernetes manifests, Docker Compose, GitHub Actions and Ansible. Its flexibility causes the famous problems:

  • Indentation is structure. One wrong space changes nesting, and tabs are not allowed.
  • Implicit types. In YAML 1.1 parsers, no, yes, on and off become booleans — the “Norway problem”, where the country code NO turns into false. Version strings such as 1.10 become the number 1.1. Quote anything that must stay a string.
  • Many ways to write the same thing — block and flow styles, several multi-line string forms — so files vary between authors.

YAML is a superset of JSON, so any JSON file is also valid YAML. JSON to YAML and YAML to JSON convert in either direction; converting YAML to JSON is also a quick way to see exactly how a parser interpreted ambiguous values.

TOML: explicit and unambiguous

TOML looks like an INI file with real types: strings are always quoted, dates are a native type, and tables are written as [section] headers. It is used by Rust’s Cargo.toml, Python’s pyproject.toml, Hugo and many CLI tools. It is excellent for flat-to-moderately-nested configuration and gets awkward for deeply nested structures, which need long dotted table names or arrays of tables ([[products]]). Convert with JSON to TOML, TOML to JSON, YAML to TOML and TOML to YAML.

INI and .env: simple key–value files

INI files have sections and key=value lines but no standard for types or nesting; each program interprets them differently. INI to JSON shows how values would be read with type detection.

.env files hold environment variables for an application, typically secrets and per-environment settings. Everything is a string, nesting is expressed with naming conventions such as DB_HOST or DB__HOST, and the file must never be committed to version control. .env to JSON and JSON to .env convert in both directions.

Which should you use?

SituationGood choice
Data exchanged between programsJSON
Config edited by people, with comments, moderately nestedTOML
Ecosystem already standardised on it (Kubernetes, CI)YAML
Secrets and per-environment values.env (or a secrets manager)
Legacy Windows or PHP applicationsINI

Converting safely

  1. Comments are lost when converting to JSON, which has none. Keep the original if comments matter.
  2. Check types after converting from YAML: look for booleans and numbers that should have been strings.
  3. TOML cannot represent null; null values must be removed or replaced.
  4. Mixed-type arrays are allowed in JSON and YAML but restricted in older TOML versions.
  5. Dates are native in YAML and TOML but become strings in JSON.

All SnipFerry converters run in your browser, which matters for configuration files that often contain hostnames, keys and passwords.