Open tools · 0

About

JSON to YAML

Paste JSON, or drop a .json file, and the YAML is written as you type, with the indentation you choose. A string that a YAML reader would take for something else, such as "NO", "on", "1.0" or "2024-01-01", is put in quotes, so PyYAML, Ansible and Kubernetes read the same text your JSON held.

What it does

  • A whole number too long for JavaScript is written digit for digit, and flagged, since JSON.parse would round it.
  • A string with line breaks becomes a block that reads line by line, not one long quoted line of escape codes.
  • A string holding a tab goes in double quotes, because PyYAML and Go’s YAML library refuse a tab in a plain value.
  • Long strings stay on one line: nothing is folded at 80 characters.
  • Accents and emoji are written as themselves, not as escape codes.
  • An array at the top becomes a list of dashed items, and empty ones stay [] and {}.
  • A key written twice keeps its last value, as JSON.parse would, and its line is pointed out.

How to use it

  1. Paste the JSON, or drop the file on the window.
  2. Pick an indent of 2 or 4 spaces, and Sort keys if you want them A to Z.
  3. Read any Careful notes under the result.
  4. Copy the YAML, or download it under the same name ending in .yaml.

What it does not do

  • JSON with comments or trailing commas: JSON does not allow them, so reading stops at the first one and names its line, for the JSON Formatter to repair.
  • Several documents split by ---: one JSON value makes one YAML document, so an array at the top stays a list.
  • Objects on one line in braces: Kubernetes and Compose files are written in block style, so nested objects go on lines of their own.

Questions

Why are some of my strings in quotes?

Because a YAML reader would otherwise take them for something else. YAML 1.1, which PyYAML, Ansible and many Kubernetes tools follow, reads NO, off and y as booleans, 2024-01-01 as a date and 012 as an octal number. Quoted, they stay the strings your JSON had.

Is JSON already valid YAML?

Nearly always: YAML 1.2 was designed so that a JSON file is also a YAML file. Converting gives the indented form people read and edit, and quotes the values an older YAML 1.1 reader would misread.

What happens to null and empty strings?

A null is written as null, the spelling every YAML version agrees on. An empty string stays "" in quotes, since a key with nothing after it would read as null.

Can I turn the YAML back into JSON?

Yes. Swap puts the YAML in the box and converts it the other way, with the same numbers and strings. Comments you add on the YAML side are reported, because JSON has nowhere to put them.

Everything here runs in your browser. Nothing you type, paste or open is uploaded, and there is no account and no queue. How that works.

Often used with

  • JSON Formatter: a file with comments or trailing commas repaired first
  • Text Compare: the YAML set beside the version already in the repository

More in Converters

  • Unit Converter: Convert length, weight, temperature, volume, area, speed, data size and nine more quantities, both ways, with the formula.
  • Base64 Encode & Decode: Encode text or files to Base64 and decode it back: URL-safe, MIME line breaks, data URIs, and images you can preview.
  • CSV Viewer & Editor: Open a CSV, Excel or JSON file as a table, tidy it (spaces, duplicates, garbled letters, dates and numbers) and save it as CSV, .xlsx or JSON.

All toolsAbout utilbrewPrivacy