webtools

JSON to YAML Converter

Private: nothing leaves your browser

JSON
output

                  

Paste YAML on the left and the JSON appears on the right.

Paste JSON and get readable YAML: indentation instead of braces, no quotes where none are needed, and multi-line strings written as proper blocks. It runs on your own device, so an API response with real data in it stays with you.

About converting JSON to YAML

JSON is what programs emit, and it is not pleasant to edit by hand: every string quoted, every level in braces, no comments and no forgiveness about a trailing comma. YAML holds the same information with the structure carried by indentation, which is why configuration files ended up written in it. Converting an example response, a package file or a policy document into YAML is usually the first step to turning it into something a person maintains. JSON that will not parse in the first place is worth putting through the JSON validator, which names the line and column that broke.

Quoting is applied only where it is needed. A plain word is left bare, but a value that would otherwise be read back as a number, a boolean or null keeps its quotes, and so does anything with leading space, a leading dash or a colon followed by a space. That is the difference between YAML that round trips and YAML that quietly changes meaning, and you can check it here with Result to input.

Strings with line breaks in them are written as a |- block rather than one long line full of escaped newlines, which is the main reason converted YAML is easier to read than the JSON it came from.

How to convert JSON to YAML

  1. Paste your JSON into the left box. The YAML appears on the right as you type.
  2. If the JSON will not parse, the status line repeats your browser's own message, including the position.
  3. Switch to YAML to JSON to go back the other way.
  4. Press Result to input and then convert again to prove the file survives a round trip unchanged.
  5. Press Copy to take the result.

Common questions about JSON to YAML

Where does the conversion actually run?

No. The conversion is JavaScript running on this page, so the data stays on your own device. Nothing is sent, logged or stored, and the page keeps working with your connection switched off. That makes it safe for a real API response rather than a made-up example.

Why are some values quoted and others not?

Quotes are added only where leaving them off would change the value. The string "123" must stay quoted or it comes back as a number, and the same goes for "true", "null", anything starting with a dash or a bracket, anything with meaningful leading or trailing spaces, and anything containing a colon followed by a space. Everything else is left bare so the result is easy to read.

How are nested arrays and objects written?

As indented blocks, two spaces per level, with each array item on a line starting with a dash. An object inside an array is written in the compact form, with the first key on the same line as the dash, which is how people write it by hand. An empty object comes out as {} and an empty array as [], since there is no block form for either.

What happens to a string containing newlines?

It becomes a |- block scalar, with the text laid out on its own indented lines. The alternative would be one very long quoted line full of backslash-n, which is legal but unreadable. The - means no newline is added at the end, so the value comes back exactly as it went in.

Can I add comments to the result?

Yes, once it is YAML. Anything after a # is a comment, and that is one of the main reasons to convert a config out of JSON in the first place. Bear in mind that converting back to JSON will drop them again, since JSON has nowhere to put them.

Next

Related tools

All Dev tools