YAML to JSON & JSON to YAML

Paste YAML or JSON in the left pane; direction is detected from the text. Convert, then copy from the output.

YAML and JSON as configuration languages

Both formats express trees of maps, lists, and scalars. JSON is strict: double-quoted keys and strings, no comments, no trailing commas. YAML adds human-oriented syntax—indentation for nesting, optional quotes, comments, and anchors—while every JSON document is also valid YAML 1.2.

DevOps pipelines (Kubernetes, GitHub Actions, Helm values) and many Spring-style configs prefer YAML; REST mocks, browser devtools, and jq pipelines usually consume JSON. Conversion is about the shared data model, not about preserving YAML-only features such as comments, merge keys, or custom tags.

YAML and JSON — background

Shared data model

  1. Maps (objects) become JSON objects or YAML mappings keyed by indentation.
  2. Lists become JSON arrays or YAML sequences with - items.
  3. Scalars: strings, numbers, booleans, and null map directly when syntax is unambiguous.
  4. JSON is a syntactic subset of YAML; a .json file parsed as YAML yields the same structure for typical configs.

What YAML adds beyond JSON

  1. Line comments (# …) and block comments are ignored by JSON entirely.
  2. Anchors (&), aliases (*), and merge keys (<<) are YAML-specific and do not round-trip to JSON.
  3. Unquoted strings, multiline literals (| and >), and flexible boolean tokens (yes/no) depend on the YAML engine.
  4. Multiple documents in one file use --- separators; JSON is one value per document.

Whitespace and typing pitfalls

  • YAML nesting is defined by spaces (tabs are discouraged); inconsistent indent breaks parsing.
  • Leading-zero IDs and very long digit strings may parse as numbers in YAML but must stay strings in many APIs—quote them in YAML before exporting JSON.
  • Multiline | and > blocks become JSON strings with embedded newlines; escaping differs from single-line JSON strings.
  • Null, true, and false have YAML and JSON spellings; quoted "true" stays a string in both worlds.

Kubernetes and CI context

  • Manifests and workflow files are YAML-first; admission controllers and policy tools often want JSON snapshots for tests.
  • Helm values and docker-compose are YAML maps; comparing them to API JSON responses requires the same logical fields, not identical formatting.
  • One manifest per conversion keeps --- multi-doc files predictable; merge results in your editor or VCS.

Where conversion fits

Policy and schema checks

OPA, JSON Schema, or OpenAPI examples often assume JSON while clusters store YAML—structural conversion clarifies fields without retyping.

Fixtures across stacks

Share one logical object between Go testdata (YAML), Jest (JSON), and Python configs by converting representation, not semantics.

Frequently asked questions

Is YAML a superset of JSON?
Every JSON text is valid YAML 1.2 for the same data, but YAML adds comments, anchors, and alternate scalar syntax. Converting YAML to JSON keeps maps, lists, and scalars—not comments or anchors.
Why do YAML comments disappear in JSON?
JSON has no comment syntax. Comments exist only in the YAML source; store YAML in git if comments document intent.
How are booleans and null handled?
YAML true/false/null become JSON true/false/null when unambiguous. Quoted "yes" or "no" remain strings. Unquoted yes/no may parse as boolean in some YAML engines—quote if you need strings.
Can anchors and merge keys round-trip?
No. Anchors (&), aliases (*), and merge keys are expanded to plain structure in JSON and cannot be reconstructed automatically.
What happens to multiline YAML strings?
Literal (|) and folded (>) blocks become JSON strings containing newline characters. Downstream tools must accept escaped or raw newlines per their JSON parser.
Why might numbers change appearance?
YAML may interpret long unquoted digit runs as integers; JSON Schema might require string IDs. Quote identifiers in YAML before converting.
Multiple --- documents in one file?
Treat each document separately. JSON output is one value per run; combine arrays or objects manually if your workflow needs a bundle.
When should I use JSON formatter instead?
When input is already strict JSON and you need pretty-print, minify, tree view, or JSON to XML/YAML from a parsed tree, use JSON formatter & beautifier. This page is for YAML and JSON representation swaps.