OKfmt

JSON/YAML/TOML Configuration Comparison: A Developer's Selection Guide

This article compares the design, syntax and ecosystem of three mainstream configuration formats, helping developers select a suitable configuration file format for new projects.

Diperbarui 2026-08-19

Core Design Philosophies of the Three Formats

Originating from JavaScript, JSON was designed as a lightweight cross-platform data interchange format. Its syntax rules are based on the ECMAScript standard, and it prioritizes reliability for machine parsing. RFC 8259 explicitly defines its core purpose as cross-system transmission of structured data.

YAML, whose full name is YAML Ain't Markup Language, is positioned as human-readable configuration data. It prioritizes lowering the barrier for manual editing, simplifies hierarchical writing through indentation-based structure, and is suitable for scenarios where non-technical personnel need to edit configurations.

TOML, whose full name is Tom's Obvious, Minimal Language, is designed as a configuration format with clear semantics. It advocates that configuration semantics should be parsable unambiguously, and avoids ambiguous interpretation through explicit sectioning and key-value structure.

Comparison of Core Syntax Features

Differences in common features between the three formats directly affect the configuration writing experience. JSON does not reserve space for comments, and most parsers do not support comment syntax. Both YAML and TOML natively support single-line and multi-line comments, making it convenient to write configuration descriptions.

Differences in multi-line strings and date types correspond to requirements of different scenarios: YAML is suitable for writing multi-line descriptions or template content, while JSON requires escape processing for newlines, which has consistent compatibility but is cumbersome to write.

Syntax FeatureJSONYAMLTOML
Native comment supportNoYesYes
Native multi-line stringNoYes, two stylesYes, three styles
Native date-time typeNo, string onlyYes, ISO 8601 formatNo, string only
Syntax dependencyDelimited by curly braces and bracketsIndentation-sensitiveDelimited by section symbols

Classic Issues of Common Parsing Ambiguity

The most well-known issue of JSON is the lack of official comment support. If some developers add comments to JSON, switching to a standard parser will directly trigger a parsing failure, resulting in the configuration cannot be loaded. Some derivative solutions such as JSONC add comment support, but they have not been incorporated into the official standard.

YAML has the well-known Norway problem: when a string is in the 20:03 format, some parsers will automatically convert it to a Base60 time type, resulting in the value 1203, which does not match the expected string value. This problem originates from YAML's implicit type conversion rules.

TOML does not have implicit type conversion. All value types are explicitly marked by syntax, and no type is automatically inferred. Therefore, it does not have similar ambiguity issues, and the type result matches the writer's expectation.

Adoption in Mainstream Development Ecosystems

There is a clearๅˆ†ๅฑ‚ in the adoption level of the three formats in different technology stacks. The following table summarizes the mainstream status of each format by application scenario, as well as the maturity of parsers in the corresponding ecosystem.

  • Docker Compose uses YAML as its configuration format, supporting multi-service declaration and hierarchical configuration
  • package.json in the npm ecosystem uses JSON to store project metadata and dependency configuration, which is the standard for Node.js projects
  • Python PEP 621 specifies pyproject.toml as the configuration standard for Python projects, replacing the old setup.py configuration
  • GitHub Actions workflow configuration uses YAML format, and most tools in the cloud-native domain use YAML

Information Retention Boundaries for Format Interconversion

When converting between different formats, there are fixed boundaries for information loss. The OKfmt format conversion tool retains valid information based on syntax support, and discards incompatible content. When converting JSON to YAML or TOML, no native information is lost, and all structures can be completely mapped.

When converting YAML to JSON, YAML's comments and native date type information will be lost, as JSON does not support these two features. When converting TOML to JSON, only comments are lost, and all structure types can be completely mapped. When converting YAML to TOML, native date types will be converted to strings in the corresponding format, and comments can be completely retained.

Tanya Jawab Umum

Which format should I choose for configuration in a new project?

You can choose according to ecosystem requirements: use JSON by default for Node.js projects, use YAML by default for cloud-native configurations, use TOML by default for Python projects, and for custom projects you can choose according to team habits.

How to solve the problem that JSON does not support comments?

You can write in JSONC format and convert to standard JSON after building, or put description information into a dedicated description field. The specific solution depends on the parser used by the project.

How to avoid parsing errors caused by YAML indentation issues?

You can use a uniform 2-space indentation and disable editor tab replacement. Some editor plugins can check indentation in real time, and you can verify structural validity after converting to JSON.