Skip to content
๐Ÿงพ

JSON to YAML Converter

Convert JSON to YAML and back again, with validation on both sides.

Runs in your browser

Updated

Converting JSON to YAML

Input lines

0

Output lines

0

Keys

0

Round trip

-

The reader supports the subset of YAML that shows up in configuration: nested objects and arrays by indentation, quoted and plain scalars, numbers, booleans, and null. Tab indentation, block scalars and non-JSON flow style report an error; anchors, aliases and a second document are not resolved and pass through as plain text. Strings that look like numbers or booleans are quoted on output, so a type survives the round trip. Both directions run in your browser.

Two directions, one small subset

JSON to YAML parses the input with JSON.parse and prints YAML with two-space indentation; YAML to JSON walks the indentation and prints with JSON.stringify at two spaces. The YAML side is a small reader: nested mappings and sequences by indentation, plain and quoted scalars, numbers, booleans and null. Four counters show input lines, output lines, keys and round-trip status.

A worked example

The Sample button loads 13 lines of JSON and converts them into 20 lines of YAML with 15 keys, and the round trip counter reads "clean". Sequences of objects use a lone dash with the fields indented beneath, so each people entry becomes a dash followed by name and active.

Strings keep their quotes

The emitter and the reader are separate functions. A JSON string is written plain only when YAML would read it back as the same string: {"zip":"01234"} comes out as zip: "01234", {"flag":"yes"} as flag: "yes", and an empty string as "". Anything that looks like a number, a boolean or null, begins with punctuation, or contains a colon-space or a space-hash is double-quoted, so converting there and back returns the same types and the round trip counter reads "clean".

What the reader refuses

The parser stops on tab indentation, naming the line, and on block scalars introduced by a pipe or a greater-than sign. Flow style works only when it is valid JSON, so [1, 2] converts while [a, b] errors. Comments are ignored and three-dash separators are skipped, folding a second document into the first. Anchors are not resolved; &anchor and *alias stay as literal text.

Where it stops

  • Numbers are emitted as JavaScript numbers, so very long integers lose precision.
  • Anchors, aliases and multi-document files are handled badly, without a warning.
  • Comments and quoting style are not preserved.
  • No file upload, no download and no formatting options.

Questions people ask

Will my quoted number turn into a number?

No. Strings that look like numbers are re-quoted on output, so a postal code or an account ID keeps its leading zeros through a round trip. Real JSON numbers stay unquoted and are read back as numbers.

Is the YAML checked against the specification?

Only against this reader's subset, so a document that converts here may trip a stricter parser. To check JSON is well formed first, use the JSON validator.