DataSwitch Pro Private, in-browser data converter

JSON to YAML Converter

Turn JSON into clean, human-readable YAML for configuration files and infrastructure as code.

Copied to clipboard!
Rows
0
Columns
0
Delimiter
—
Input Size
0 B
Output Size
0 B
Speed
0 ms

How to convert JSON to YAML

Updated · 3 min read

YAML is the language of modern configuration: Kubernetes manifests, Docker Compose, GitHub Actions, GitLab CI, Ansible and OpenAPI specs. It is easier to read and comment than JSON, and every JSON document is also valid YAML data. This converter produces idiomatic YAML with two-space indentation, preserves key order and quotes only what needs quoting.

  1. Paste JSON or drop a .json file.
  2. The YAML appears instantly; key order is preserved.
  3. Check values that were quoted — they would otherwise change type in YAML.
  4. Copy the YAML or download a .yaml file.

Example

JSON input

{
  "services": {
    "web": {
      "image": "nginx:1.27",
      "ports": ["8080:80"],
      "environment": { "MODE": "production", "DEBUG": "false", "COUNTRY": "NO" }
    }
  }
}

YAML output

services:
  web:
    image: nginx:1.27
    ports:
      - '8080:80'
    environment:
      MODE: production
      DEBUG: 'false'
      COUNTRY: 'NO'

Strings like "false" and "NO" are quoted in the YAML output. Left unquoted, many YAML parsers would read them as the boolean false — the infamous "Norway problem" where the country code NO turns into false.

Your data stays on your device. The conversion runs in JavaScript inside this tab — files and pasted text are never uploaded to DataSwitch Pro.

How values are written

Where YAML is used

Kubernetes and Helm, Docker Compose, GitHub Actions and GitLab CI pipelines, Ansible playbooks, OpenAPI/Swagger definitions, Home Assistant, static site generators such as Jekyll and Hugo front matter, and countless application config files. Converting from JSON is a quick way to start one of these files from an API response or generated data.

Adding comments after conversion

JSON has no comments, so the generated YAML has none either. One of the main reasons to switch to YAML is that you can now document your configuration with # comments.

Real-world examples

Write a Docker Compose file from JSON

Some tools export settings as JSON, while Docker Compose, Kubernetes and GitHub Actions expect YAML. Converting avoids retyping and indentation mistakes, and values such as 8080:80 are quoted where YAML needs it.

JSON

{
  "services": {
    "web": {
      "image": "nginx:1.27",
      "ports": ["8080:80"],
      "restart": "unless-stopped"
    }
  }
}

YAML

services:
  web:
    image: nginx:1.27
    ports:
      - '8080:80'
    restart: unless-stopped

Make an API response readable

YAML drops braces and quotes, so a deeply nested API response becomes much easier to read and to paste into documentation or a support ticket.

JSON

{"user":{"id":7,"name":"Sam","roles":["editor","billing"],"active":true,"zip":"02134"}}

YAML

user:
  id: 7
  name: Sam
  roles:
    - editor
    - billing
  active: true
  zip: '02134'

Common errors and how to fix them

Strings like "yes", "no" or "02134" appear in quotes

They are quoted on purpose. Unquoted, older YAML parsers read yes as a boolean and 02134 as a number, which would change your data.

The YAML is rejected by the target tool

The conversion is valid YAML; the tool may expect a different structure, such as a list under ports. Compare with the tool's documented example.

Comments are missing

JSON cannot contain comments, so there are none to carry over. Add # comments to the YAML after converting.

Key order changed

It does not — keys are written in the same order as in the JSON. If the order looks different, check whether the source JSON was already sorted.

Related guides

Convert JSON to YAML in code

For one-off files the tool above is quickest. To automate the same task in a script or pipeline, these snippets are a good starting point.

Python (PyYAML)

import json
import yaml  # pip install pyyaml

with open("data.json", encoding="utf-8") as f:
    data = json.load(f)

print(yaml.safe_dump(data, sort_keys=False, allow_unicode=True))

Command line (yq)

# mikefarah/yq v4
yq -p json -o yaml '.' data.json > data.yaml

Node.js (js-yaml)

import yaml from "js-yaml";  // npm install js-yaml
const out = yaml.dump(JSON.parse(text), { noRefs: true });

Frequently asked questions

Why are some strings in quotes?

Because without quotes YAML would interpret them as another type — for example yes, no, on, true, null or numbers with leading zeros. Quoting keeps them as strings, exactly as in your JSON.

Is key order preserved?

Yes. Keys appear in the same order as in the JSON input.

Can I convert a JSON array?

Yes. A top-level array becomes a YAML list. Each element starts with a dash.

Can I convert back to JSON?

Yes. Use the swap button or the YAML to JSON converter.

Is my configuration uploaded?

No. Conversion happens in your browser, so secrets in config files stay on your device.

Related converters