1. Home
  2. Guides
  3. JSON vs YAML: differences, when to use each and how to convert
JSON

JSON vs YAML: differences, when to use each and how to convert

Which format to pick for config and APIs, and how to switch between them.

12 October 20265 min read

JSON and YAML can describe the same data: objects, lists, strings, numbers and true/false values. JSON is the standard for APIs. YAML is popular for configuration files such as Docker Compose, Kubernetes and GitHub Actions. Knowing how they differ helps you pick one and convert safely.

The same data in both

// JSON
{
  "name": "nova",
  "ports": [80, 443],
  "debug": false
}

# YAML
name: nova
ports:
  - 80
  - 443
debug: false

Main differences

JSONYAML
StructureBraces, brackets and commasIndentation and dashes
CommentsNot allowedYes, with #
Quotes on stringsAlways double quotesUsually optional
ReadabilityGood for machines, noisy for peopleEasier to read and edit by hand
StrictnessVery strict, easy to parseFlexible, easier to get subtly wrong
Typical useAPIs, data exchange, JS appsConfig files, CI pipelines, Kubernetes

YAML is a superset of JSON in most practical cases, so many parsers read JSON as YAML.

Convert JSON to YAML in your browser, keeping the structure intact.Open JSON to YAML →

YAML gotchas

  • Indentation is meaning. Use spaces, not tabs, and keep the same width. One extra space can change the structure.
  • Unquoted values can change type. no, off or yes may be read as booleans by some parsers (the “Norway problem”: the country code NO became false). Quote values like these.
  • Numbers with leading zeros such as 0123 can be read as octal. Quote them if they are IDs.
  • Colons and hashes in text. A value containing : or # needs quotes.

JSON gotchas

  • No trailing commas and no comments. Errors are explained in common JSON errors.
  • Keys must be double-quoted strings.
  • Big integers beyond 2⁵³ lose precision in JavaScript.

Which should I use?

  • API responses and requests: JSON.
  • Files that people edit and comment: YAML.
  • Data between programs, where safety and speed matter: JSON, with a format check using the JSON Formatter.

To go back, use YAML to JSON. Comments in YAML cannot be kept in JSON, so they are dropped.

Frequently asked questions

Is YAML better than JSON?

Neither is better overall. YAML is nicer to write by hand and JSON is safer to exchange between systems.

Does converting lose anything?

Comments and YAML anchors are not kept when you convert to JSON. The data values themselves are.

More guides

Free for everyone, kept free by you.

No paywall, no sign-up and no watermarks. If a tool saved you time, you can chip in any amount by UPI to keep Nova Free Tools running.

Esc
↑↓ move↵ openEsc close