JSON to YAML

Turn JSON into readable YAML for config files and manifests.

Reverse
Input
JSON input
Output
Result
Options

Spaces per level of nesting.

Further reading

  • How to convert JSON to YAMLConvert JSON to YAML: review quoting, indentation, multiline values, parser-version differences and the limits of a parse-and-serialize round trip.

About this tool


YAML can represent the objects, arrays, strings, numbers, booleans and null values produced by parsing JSON. This converter parses with JSON.parse and emits YAML 1.2; duplicate keys and numeric precision can already be lost during parsing. What changes is the syntax: non-empty collections normally use indentation and hyphens rather than braces, brackets and commas.

The usual reason to convert is configuration. Kubernetes manifests, GitHub Actions workflows, Docker Compose files and Ansible playbooks all expect YAML, while APIs and code tend to produce JSON. YAML also supports comments, which JSON does not, so converting is often the first step before documenting a config by hand.

How to use it

  1. Paste or upload JSONDrop a .json file onto the input pane or paste the text directly.
  2. ConvertPress Convert to YAML, or use Ctrl+Enter.
  3. Check the indentationTwo spaces is the YAML convention and the default here; adjust it in Options if your project differs.
  4. Copy or downloadSave the result as a .yaml file, or copy it into your config.

Worked examples


Each example below is executed against this tool by the test suite, so what you see is what the tool actually produces.

Nested object with an array and a null

Input

{"name":"John","age":30,"tags":["a","b"],"meta":null}

Output

name: John
age: 30
tags:
  - a
  - b
meta: null

Braces and commas disappear; the array becomes a hyphenated block.

Strings that need protecting

Input

{"zip":"01234","flag":"true","version":"1.0"}

Output

zip: "01234"
flag: "true"
version: "1.0"

Each value is quoted so it stays a string. Without quotes, a YAML 1.2 core-schema parser would read these as 1234, a boolean and a float.

What to watch for


The details that decide whether a conversion is correct, and where information can be lost without any error being raised.

Objects become indented mappings
Each JSON key becomes a YAML key followed by a colon and a space. Nesting is expressed purely by indentation, so the braces disappear. YAML forbids tabs for indentation, only spaces are legal, so this converter always emits spaces regardless of your editor settings.
Arrays become block sequences
Array elements are written as hyphen-prefixed lines rather than a bracketed list. An array of objects produces a hyphen followed by the first key on the same line, with the remaining keys aligned beneath it. An empty array has no block form, so it is emitted as the flow form [], and an empty object as {}.
Strings are quoted only when they must be
Most strings need no quotes in YAML, which is much of why it reads well. Quotes are added when the value would otherwise change type or break parsing: "true", "null", "1.5", "007", anything starting with a special character such as *, & or %, and strings with leading or trailing spaces. This is what keeps a zip code like 01234 from becoming the number 1234 on the way back.
Null, booleans and numbers
JSON null becomes YAML null. Note that YAML also treats an empty value and the literal ~ as null, so a hand-edited file can produce a null the original JSON never contained. Booleans stay true and false. Numbers are emitted from JavaScript IEEE 754 values, so numeric spelling can change and large integers or high-precision decimals may already have been rounded. An overflowing value such as 1e400 becomes YAML .inf, which cannot be represented as a finite JSON number on return.
What JSON cannot express
The converter does not generate anchors, aliases, multiple documents, comments or custom tags. Its output targets YAML 1.2. Older YAML 1.1 parsers can interpret plain strings such as yes differently, so use a compatible parser. Round-tripping concerns parsed values, not the original JSON text; duplicate keys, number precision and overflowing numbers require special care.

Limitations


  • Comments cannot be generated, because JSON has none to convert.
  • Anchors, aliases and multiple documents are never produced; the output is a plain YAML subset.
  • JSON.parse keeps the last duplicate key and uses JavaScript IEEE 754 numbers. Large integers and high-precision decimals may be rounded, and overflowing numbers do not round-trip as finite JSON numbers.
  • Processing happens in your browser, so very large inputs are bounded by available memory. Files above roughly 10 MB are handled but will feel slower, and multi-hundred-megabyte files are better suited to a command-line tool.

Questions


Is converting JSON to YAML lossless?
The generated YAML targets YAML 1.2 and represents the values produced by JSON.parse, subject to JavaScript number handling. Converting back does not restore duplicate keys or numeric precision lost during parsing; overflowing numbers become null in JSON, and negative zero becomes 0. The original formatting is not preserved. YAML also has features that JSON cannot represent.
Can I add comments to the output?
Not automatically, the source JSON has none to carry over. Once converted you can add # comments freely, and they will survive in YAML but be dropped if you convert back to JSON.
Why are some of my strings quoted?
Because without quotes YAML would interpret them as another type. "true", "null", "1.5" and "007" all need quoting to remain strings. Quoting only where necessary keeps the output readable.
Does it use tabs or spaces?
Spaces, always. The YAML specification forbids tabs as indentation, so a tab-indented file is invalid YAML no matter what your editor does elsewhere.