Comparison

JSON vs YAML

JSON and YAML describe the same data model, so any JSON document is also valid YAML. JSON is stricter, faster to parse and universal for APIs. YAML supports comments, multi-line strings and less punctuation, which makes it the common choice for configuration files. Use JSON for machine interchange and YAML for files humans edit by hand.

YAML to JSON Converter

Convert YAML configuration into equivalent JSON.

Open the tool

These formats are not really competitors. YAML is a superset of JSON, so the question is rarely which can express your data — both can — but which is better suited to who or what will be reading and writing the file.

The deciding factor is usually comments. JSON has none, by design, which makes it a poor fit for configuration where explaining why a value is set matters as much as the value itself.

Where JSON wins

JSON has one obvious way to write anything, which makes it fast to parse and effectively impossible to misinterpret. Every language ships a parser in its standard library, and no API has to explain which JSON dialect it speaks.

  • Universal support with no dialect ambiguity.
  • Faster to parse, which matters at API volume.
  • No type-coercion surprises: a quoted string is a string.
  • Trivial to generate correctly from any language.

Where YAML wins

YAML was designed for humans to write. Comments, block scalars for multi-line text, anchors for reuse and the absence of brace and quote noise all make a long configuration file easier to read and review in a diff.

  • Comments, which JSON simply does not have.
  • Multi-line strings without escaping every newline.
  • Anchors and aliases for reusing a block.
  • Less punctuation, so diffs are cleaner to review.

The YAML traps

YAML's flexibility is also its liability. Historically, unquoted values were coerced aggressively: no became false, and version numbers like 1.20 lost their trailing zero. YAML 1.2 tightened this, but which rules apply depends on your parser version.

  • Significant indentation, and tabs are forbidden entirely.
  • Unquoted no, off and yes may become booleans.
  • A value like 1.20 can be read as the number 1.2.
  • Some loaders can instantiate arbitrary objects — always use a safe loader on untrusted input.

Choosing between them

Use JSON when a machine writes it and a machine reads it: API payloads, message queues, log lines, anything generated programmatically. Use YAML when a person maintains the file by hand and needs to explain their choices: CI pipelines, Kubernetes manifests, application configuration.

Example

The same data in both formats. Note the comment, which JSON cannot express at all.

JSON

{
  "service": "api",
  "replicas": 3,
  "regions": ["eu-west", "us-east"]
}

YAML

# Scaled up for the August launch
service: api
replicas: 3
regions:
  - eu-west
  - us-east

Frequently asked questions

Is JSON valid YAML?
Yes, under YAML 1.2, which was explicitly defined as a superset of JSON. Any valid JSON document can be parsed by a conforming YAML 1.2 parser. The reverse is not true — most YAML uses syntax JSON has no equivalent for.
Why does JSON not allow comments?
A deliberate design decision by its author, to keep it a pure data interchange format and stop people using comments to smuggle in parsing directives. Where you need commented JSON, use JSONC or JSON5 and strip the comments before parsing, or use YAML.
Which is faster?
JSON, substantially. Its grammar is far simpler, so parsers do less work. For a configuration file read once at startup the difference is irrelevant; for API traffic at volume it is not.
What is the Norway problem?
In YAML 1.1, the unquoted value no was interpreted as the boolean false — so a country list containing Norway's code NO could silently become false. YAML 1.2 fixed it, but the lesson stands: quote values that could be read as booleans.
Can I convert between them safely?
JSON to YAML is always safe, since YAML can express everything JSON can. YAML to JSON can lose comments, anchors and multi-document structure, because JSON has no way to represent any of those.

Tools used in this guide

All tools →
All guides →

Last reviewed .