JSON to YAML Converter

Convert JSON to clean, readable YAML, or YAML back to JSON. Anchors, merge keys and multiple documents are handled, and values another YAML reader could misread are quoted.

Converted in your browser; nothing is uploaded.

2 spaces
YAML

This converter turns JSON into YAML for Kubernetes manifests, Docker Compose files, GitHub Actions workflows and other configuration, and turns YAML back into JSON for APIs and code. It runs in your browser with a full YAML 1.2 parser, so anchors, merge keys, block text and multi-document files are handled properly, and syntax errors are reported with the line and column.

The Same Data in JSON and YAML

{
  "name": "web",
  "replicas": 3,
  "ports": [80, 443],
  "env": {
    "DEBUG": "no",
    "TZ": "Asia/Karachi"
  }
}
name: web
replicas: 3
ports:
  - 80
  - 443
env:
  DEBUG: "no"
  TZ: Asia/Karachi

YAML drops the braces, brackets and most quotes and shows nesting with indentation instead. Lists use a dash per item. "no" stays quoted because a YAML 1.1 reader would otherwise read it as false.

Values YAML Readers Disagree On

Unquoted, these values mean different things depending on the YAML version of the program reading them:

Written asYAML 1.1 (PyYAML, Ansible)YAML 1.2
yes, no, on, offtrue / falsetext
NO (Norway)falsetext
012383 (octal)123
1:3090 (base 60)text
2024-01-01a datetext
1_0001000text

When converting JSON to YAML, strings like these are always written in quotes, so the result reads the same everywhere. When converting YAML to JSON, choose the version your tool uses to see what it will actually get.

YAML Rules That Cause Most Errors

  • Indent with spaces only. Tabs are not allowed for indentation, and items at the same level must line up exactly.
  • Put a space after the colon. key: value is a mapping; key:value is a single piece of text.
  • Quote text that starts with a special character, such as *, &, !, @, % or a backtick, and text containing : or #.
  • Keys must be unique within a mapping. A repeated key is reported as an error rather than silently using the last value.
  • For multi-line text, use | to keep line breaks or > to fold lines into one paragraph.

Anchors, Aliases and Merge Keys

YAML can name a block with &name and reuse it with *name; <<: *name merges a reused mapping into another, as Docker Compose files often do with shared settings. JSON has no such references, so the YAML to JSON conversion writes out a full copy at each use. Some files abuse this by nesting aliases so they expand to gigabytes (the "billion laughs" attack); the converter stops such files instead of freezing your browser.

Related Tools

Check and pretty-print the JSON side with the JSON formatter, generate types for it with JSON to TypeScript, or see what changed between two versions of a config file with the diff checker.

Frequently Asked Questions

How do I convert JSON to YAML?

Paste the JSON, open a .json file or load it from a URL, and the YAML appears on the right as you type. Choose 2 or 4 spaces of indentation and whether to sort keys, then copy it or download a .yaml file. JSON Lines (one JSON value per line) is accepted too.

How do I convert YAML to JSON?

Switch to YAML → JSON and paste the YAML or open a .yaml or .yml file. Anchors and aliases are expanded, merge keys (<<) are applied, and a file with several documents separated by --- becomes a JSON array with one item per document.

Why are values like no, on and 0123 written in quotes?

Because some YAML readers would change them. YAML 1.1, which PyYAML, Ansible and many older tools still follow, reads yes, no, on and off as true or false, 0123 as the octal number 83, and 1:30 as 90. Quoting keeps them as text in every reader. A well-known case is the country code NO for Norway turning into false.

What happens to comments?

JSON has no comments, so YAML comments cannot be carried over to JSON; the tool tells you when the YAML had some. Converting back to YAML cannot restore them, so keep the original file if the comments matter.

Is JSON valid YAML?

Almost always. YAML 1.2 was designed so that a JSON document is also valid YAML, so most YAML parsers can read a .json file as it is. YAML's extra features are indentation-based blocks, comments, anchors and multiple documents in one file, which JSON does not have.

Should I choose YAML 1.2 or 1.1?

Choose the version of the tool that will read the file. YAML 1.2 (from 2009) is the current version: only true and false are booleans. Pick 1.1 to see how PyYAML or Ansible would read the file, where yes, no, on and off are booleans and dates become date values.

Are large numbers kept exactly?

Yes. Integers longer than JavaScript can hold exactly, such as 64-bit IDs like 12345678901234567890, are converted digit for digit in both directions, and decimals written with trailing zeros, such as 120000.00, keep them. From YAML this works in every browser; from JSON it needs a browser that lets the page read the original number text, which recent Chrome, Edge and Firefox do.