JSON to YAML Converter

Convert JSON to block-style YAML that quotes ambiguous strings such as "yes", "true" or "1.0", or convert typical YAML config files back to JSON.

Last updated

About the JSON to YAML

Paste JSON on the left and the YAML appears on the right as you type; there is no convert button. The output uses block style with two-space indents, so {"name": "my-app", "ports": [80, 443]} becomes name: my-app followed by ports: and the two list items on their own lines. Choose YAML → JSON for the reverse direction, or press the swap button to move the output into the input box and flip the direction.

The tricky part of writing YAML by hand is knowing which strings need quotes. Unquoted yes, no, on and off are read as booleans by older YAML 1.1 parsers, 1.10 is read as the number 1.1, and 2024-05-01 may be read as a date. This converter quotes any string that looks like a boolean, null, number or date, starts with a YAML indicator such as -, * or &, contains : or #, has leading or trailing spaces, or contains a line break. A version string "1.10" therefore stays the string "1.10" after the round trip. Quoted strings use JSON-style escapes, which YAML accepts.

The YAML → JSON direction reads the YAML found in typical single-document config files, such as a Docker Compose file: nested mappings and lists, list items that are mappings, comments, quoted strings, one-line [a, b] and {a: 1} collections, and | or > block text. Values follow the YAML 1.2 core rules, so true, false and null are converted while yes and no stay strings. Features outside that subset produce an error with the line number instead of a silently wrong result. To tidy or validate the JSON side, use the JSON Formatter.

How to use the JSON to YAML

  1. 1

    Choose the direction

    Click JSON → YAML or YAML → JSON above the input box.

  2. 2

    Paste your input

    The output updates as you type. If the input cannot be parsed, the output box turns red and shows the error, with a line number for YAML problems.

  3. 3

    Swap to check a round trip

    The arrow button next to the direction switch copies the output into the input box and flips the direction, so you can confirm that converting back gives the original data.

  4. 4

    Copy the result

    Press Copy above the output box to put the converted text on your clipboard.

What it can do

Safe quoting of ambiguous strings

Strings such as "yes", "null", "8080", "1.10", "2024-05-01" or "Hello: world" are quoted so a YAML parser cannot reinterpret them.

Readable block style

Two-space indents, list items under their key, and empty lists and objects written inline as [] and {}.

Live conversion both ways

JSON → YAML and YAML → JSON update on every keystroke, with a swap button to switch between them.

Strict YAML reading

Duplicate keys, tabs used for indentation, unclosed quotes and unsupported features are reported with a line number rather than being ignored.

Limitations

  • YAML → JSON does not support anchors (&), aliases (*), tags such as !!str, complex keys (?) or several documents separated by ---. These produce an error.
  • In YAML input, strings that continue over several lines must use | or > block style; multi-line plain or quoted strings, and [ ] or { } collections spread over several lines, are not supported.
  • Comments are dropped when converting YAML to JSON, because JSON has no comments, and the YAML output never contains comments.
  • Multi-line strings in JSON are written to YAML as double-quoted strings with \n escapes, not as | blocks.
  • Numbers pass through JavaScript, so integers longer than about 15 to 16 digits lose precision in both directions.

Privacy

Conversion happens in your browser with JavaScript; the JSON or YAML you paste is not sent to FlexyPdf's servers.

Frequently asked questions

Why does some of my text have quotes in the YAML output?

Those strings would mean something else without quotes. Unquoted, "no" can become false, "8080" a number, "2024-05-01" a date and "Hello: world" a nested key. Quoting keeps them as the strings they were in your JSON.

Will yes or no in my YAML turn into true or false?

No. The YAML → JSON direction follows YAML 1.2, where only true and false (also True, TRUE, False, FALSE) are booleans. Unquoted yes, no, on and off stay strings.

Can I convert a Kubernetes file that contains several resources?

Not in one go. Files with several documents separated by --- give an error. Paste each document separately and convert them one at a time.

Why does the YAML side report an indentation error?

YAML uses indentation to show structure, and it must be spaces; tab characters are not allowed. The error also appears when a line is indented deeper than expected without a key, which usually means a misplaced list item or a string that continues onto the next line without | or quotes.

Are dates converted to a date type?

No. JSON has no date type, so an unquoted date such as 2024-05-01 in YAML stays the string "2024-05-01" in the JSON output.

Ratings & Reviews

—
No ratings yet
5
0
4
0
3
0
2
0
1
0

Rate JSON to YAML

Help others by sharing your experience. Your rating is shown without your name.

0/600