JSON to YAML Converter

Rewrite JSON as block-style YAML for config files and manifests.

About JSON to YAML Converter

Paste JSON and get block-style YAML with two-space indentation, ready to drop into a Kubernetes manifest, a Compose file or any other YAML config.

How to use

  1. Paste JSON, or load a .json file (up to 5 MB) with the file picker or by dropping it on the page.
  2. The YAML appears as you type. A JSON syntax error is shown under the input with its line and column.
  3. Copy the YAML, or Download it as .yaml named after the loaded file.

The page opens on JSON → YAML. To go the other way, switch the direction to YAML → JSON, or to Auto to have it detected.

How JSON becomes YAML

  • Objects become mappings and arrays become - lists, in block style, indented two spaces. Key order is kept as written.
  • Strings are left unquoted when that is safe. A string that YAML would otherwise read as something else is put in single quotes: "1.10" becomes '1.10', "yes" becomes 'yes' and "01234" becomes '01234', so version numbers and postcodes stay strings.
  • A string containing line breaks becomes a |- block scalar, one line of text per line.
  • Long strings are not wrapped.
  • null is written as null, an empty object as {} and an empty array as [].
  • Numbers are written as JavaScript reads them, so 1.0 becomes 1. An integer beyond 2^53 loses precision, and the page warns when it sees one.

Example

{
  "name": "api",
  "replicas": 3,
  "version": "1.10",
  "ports": [{ "port": 80, "protocol": "TCP" }]
}
→
name: api
replicas: 3
version: '1.10'
ports:
  - port: 80
    protocol: TCP

Privacy

The conversion runs in the page with js-yaml. A loaded file is read locally, no request is made, and nothing is stored.

Frequently asked questions

Do I need to convert JSON to YAML at all?
Often not. YAML 1.2 accepts JSON syntax, so most YAML parsers will read a JSON document as it is. Converting is worth it when people will read or edit the file: block-style YAML drops the braces, brackets and most quotes, and allows comments.
Why are some values quoted in the YAML output?
Because without quotes a YAML parser would change their type. The JSON string "true" would become a boolean, "1.10" the number 1.1 and "no" a boolean in older YAML 1.1 parsers. Quoting keeps them strings, exactly as they were in the JSON.
How do I convert JSON to YAML on the command line?
With yq: yq -P file.json prints the YAML. With Python and PyYAML: python -c "import sys,json,yaml; print(yaml.safe_dump(json.load(sys.stdin), sort_keys=False))" < file.json.
Can the YAML be converted back to the same JSON?
Yes. JSON to YAML loses nothing except number spelling such as 1.0 against 1, so converting the output back gives the same data. The opposite trip is not lossless: YAML comments and anchors have no JSON form.