Dev ToolsMarch 30, 2026

JSON to YAML Converter Guide: Syntax, Differences & Migration Tips

By The hakaru Team·Last updated March 2026

Quick Answer

  • *YAML is a superset of JSON since YAML 1.2 — all valid JSON is valid YAML.
  • *YAML uses indentation instead of braces, supports comments with #, and is more human-readable.
  • *94% of Kubernetes users write configs in YAML over JSON (2025 CNCF Survey).
  • *Watch out for the Norway problem — unquoted “no” in YAML becomes boolean false.

JSON vs YAML: Side-by-Side Comparison

Both JSON and YAML are data serialization formats. JSON was formalized by Douglas Crockford in 2001 and standardized as RFC 8259. YAML (originally “Yet Another Markup Language,” later backronymed to “YAML Ain't Markup Language”) first appeared in 2001 and reached version 1.2 in 2009.

FeatureJSONYAML
CommentsNot supportedSupported (#)
ReadabilityGood for small docsBetter for large/nested docs
Data typesstring, number, boolean, null, array, objectAll JSON types + dates, timestamps, binary
Multi-line stringsEscaped newlines onlyBlock scalars (| and >)
Anchors/aliasesNot supportedSupported (& and *)
Trailing commasNot allowedNo commas needed
File extension.json.yaml or .yml
Parse speedFaster (simpler grammar)Slower (complex grammar)

According to the 2025 Stack Overflow Developer Survey, 72% of developerswork with JSON regularly, while 48% work with YAML. The overlap is significant — most developers use both, choosing the format based on context.

When to Use JSON

JSON dominates machine-to-machine communication. Use it for:

  • REST APIs: JSON is the de facto standard. Over 90% of public APIs use JSON for request and response bodies (RapidAPI 2024 State of APIs report).
  • Data interchange: Every programming language has a fast, built-in JSON parser. YAML parsers are external dependencies in most languages.
  • Browser/frontend: JavaScript natively parses JSON with JSON.parse(). No library needed.
  • Strict schemas: JSON Schema is widely supported for validation. YAML has no equivalent standard.

When to Use YAML

YAML excels where humans read and edit config files. Use it for:

  • Kubernetes manifests: 94% of K8s users prefer YAML (CNCF 2025 Survey).
  • CI/CD pipelines: GitHub Actions, GitLab CI, CircleCI, and most CI tools use YAML configs.
  • Docker Compose: The standard docker-compose.yml format.
  • Ansible playbooks: Ansible is YAML-native for infrastructure automation.
  • Application configs: Rails, Spring Boot, Hugo, and many frameworks prefer YAML for settings.

Common Conversion Pitfalls

The Norway Problem

YAML 1.1 treats unquoted no, yes, on, off, true, and false as booleans. This means the ISO 3166-1 country code for Norway (NO) becomes false when parsed. YAML 1.2 fixed this, but many parsers still default to 1.1 behavior. Always quote strings that could be interpreted as booleans.

Indentation Errors

YAML requires spaces for indentation — tabs are not allowed. A single misaligned space can change the structure entirely. The YAML spec recommends 2-space indentation, which is also the most common convention in Kubernetes and Docker Compose files.

Unquoted Numbers and Versions

Version strings like 1.10 become the float 1.1 in YAML if unquoted. Octal numbers (e.g., 0123) are interpreted differently. Phone numbers lose leading zeros. Always quote values that look like numbers but are actually strings.

Multi-line String Conversion

JSON uses \n for newlines within strings. YAML offers two block scalar styles: literal block (|) preserves newlines exactly, and folded block (>) joins lines with spaces. Choosing the wrong style changes line break behavior.

Conversion Rules Reference

JSONYAML EquivalentNotes
{"key": "value"}key: valueQuotes optional for simple strings
{"n": 42}n: 42Numbers are unquoted
{"b": true}b: trueSame boolean literals
{"x": null}x: null or x: ~Tilde is YAML shorthand for null
[1, 2, 3]- 1\n- 2\n- 3Block or flow style
Nested objectsIndented keys2-space indent is conventional

YAML Features with No JSON Equivalent

Comments

YAML supports inline comments with #. This is the single biggest reason teams choose YAML for configuration. Documenting why a setting exists is critical for maintainability. Standard JSON has no comment syntax — Douglas Crockford intentionally excluded them.

Anchors and Aliases

YAML anchors (&) and aliases (*) let you define a value once and reference it elsewhere, reducing duplication. This is heavily used in CI/CD configs where multiple jobs share settings. JSON requires duplicating the data.

Multiple Documents

A single YAML file can contain multiple documents separated by ---. Kubernetes uses this pattern to define multiple resources in one file. JSON requires separate files or wrapping in an array.

Convert between JSON and YAML instantly

Use our free JSON to YAML Converter →

Frequently Asked Questions

What is the difference between JSON and YAML?

JSON uses braces, brackets, and quotes for structure. YAML uses indentation and is designed to be more human-readable. JSON is a strict subset of YAML (since YAML 1.2), meaning all valid JSON is also valid YAML. JSON is better for APIs and machine-to-machine data exchange, while YAML is preferred for configuration files that humans edit frequently.

Is YAML a superset of JSON?

Yes, since YAML 1.2 (released in 2009). Every valid JSON document is also a valid YAML document. This means you can paste JSON directly into a YAML file and it will parse correctly. The reverse is not true — YAML features like anchors, aliases, comments, and multi-line strings have no JSON equivalent.

Why does Kubernetes use YAML instead of JSON?

Kubernetes accepts both JSON and YAML, but the community overwhelmingly uses YAML because it supports comments (critical for documenting infrastructure configs), is more readable for deeply nested structures, and requires fewer characters. The 2025 CNCF Survey found that 94% of Kubernetes users write manifests in YAML. Kubernetes internally converts all configs to JSON before processing.

What are common YAML pitfalls when converting from JSON?

The most common pitfalls are: (1) indentation errors — YAML uses spaces only, never tabs, and indentation level matters; (2) the Norway problem — unquoted “no,” “yes,” “on,” “off” are parsed as booleans, so country code “NO” becomes false; (3) unquoted strings that look like numbers — “1.0” becomes a float, version “1.10” becomes 1.1; (4) multi-line strings require special syntax (| for literal, > for folded).

Can I add comments in JSON?

Standard JSON (RFC 8259) does not support comments. This is a deliberate design decision by Douglas Crockford to prevent misuse of comments for parsing directives. YAML supports comments with the # character. Some JSON variants like JSON5 and JSONC (used by VS Code) do support comments, but they are not compatible with standard JSON parsers.