Hack the Hydra

YAML vs JSON

JSON is a strict, minimal data format that every language parses the same way, which makes it the default for APIs and data exchange. YAML describes the same data (objects, lists, strings, numbers, booleans, null) with indentation instead of brackets and allows comments, which makes it easier to write by hand for configuration files. Every JSON document is also valid YAML 1.2, but YAML has more ways to go wrong: indentation errors, values silently turned into booleans or dates, and unsafe loaders.

YAML to JSON converter →

YAML to JSON converter: the tool with a sample file converted

The same data in both formats

A small service configuration in JSON:

{
  "name": "web",
  "replicas": 2,
  "ports": [80, 443],
  "env": {"DEBUG": "false"}
}

The same thing in YAML:

# web front end
name: web
replicas: 2
ports:
  - 80
  - 443
env:
  DEBUG: "false"

YAML drops the braces, brackets, commas and most quotes, and adds a comment. Structure comes from indentation with spaces; tabs are not allowed for indentation.

Side by side

JSONYAML
CommentsNoYes (#)
StructureBraces and bracketsIndentation (spaces only)
Quotes on stringsAlwaysUsually optional
Several documents per fileNoYes (separated by ---)
Reuse a blockNoAnchors and aliases (&name, *name)
DatesNo type, use stringsSome parsers turn 2026-11-10 into a date
ParsingSimple, identical everywhereComplex, versions 1.1 and 1.2 differ
Typical useAPIs, data exchange, package.json, browser storageKubernetes, Docker Compose, GitHub Actions, Ansible, OpenAPI files

What are the YAML pitfalls?

Which one should you choose?

Converting between the two is lossless for the data itself; only YAML comments, anchors and document separators have no JSON equivalent.

Validate before you deploy

Whichever format you write, check it in CI: a JSON file is invalid if any comma or quote is missing, and a YAML file can be valid yet mean something else than you intended. Converting a YAML config to JSON and reading the result is a quick way to see exactly which values became strings, numbers, booleans or null.

FAQ

Is JSON valid YAML?

Yes for YAML 1.2: a JSON document can be read by a YAML 1.2 parser. Older YAML 1.1 parsers handle almost all JSON too, with rare edge cases.

Is YAML slower than JSON?

Parsing YAML is usually slower because the grammar is much larger. For configuration files this does not matter; for high-volume data exchange JSON is the better choice.

Can I add comments to a JSON file?

Not in standard JSON. Some tools accept JSONC or JSON5, which allow comments, but a strict JSON parser will reject them. If you need comments, YAML or a separate README is the safer option.

How do I convert YAML to JSON?

Paste the YAML into the YAML to JSON converter on this site; the JSON to YAML converter does the opposite. Both run in your browser.

Last updated: November 2026. Facts about third-party tools come from their public repositories and documentation. Check licenses before commercial use.

Try it now

YAML to JSON converter →

JSON to YAML converter →

JSON formatter and validator →