JSON to YAML Converter

Paste JSON and get valid, readable YAML. Choose indentation and quoting; the output updates as you type.

23 lines

Need the opposite direction? Convert YAML to JSON.

What this converter does

Most APIs and command-line tools speak JSON, but most configuration files are written in YAML: Kubernetes manifests, Docker Compose files, GitHub Actions workflows, Ansible playbooks and Helm values. When you have an API response, a kubectl get -o json dump or a JSON config and need it in YAML, retyping it by hand is slow and error-prone because YAML is sensitive to indentation and to how strings are quoted.

This tool parses your JSON and serialises it with the yaml library, a complete implementation of the YAML specification. That means the output is always valid YAML and, more importantly, it means exactly the same data as the JSON you pasted: a string stays a string, a number stays a number.

How to use it

  1. Paste your JSON into the JSON input box, or press Load example to see a Kubernetes Deployment.
  2. The YAML output updates as you type. If the JSON is invalid, the error message under the input shows the line and column of the problem.
  3. Adjust Indent, String quoting, YAML 1.1 safe and Sort keys A–Z if needed.
  4. Press Copy YAML or Download .yaml.

Worked example

Input JSON (a shortened container definition):

{
  "name": "web",
  "image": "nginx:1.27",
  "ports": [{ "containerPort": 80 }],
  "env": [
    { "name": "FEATURE_FLAG", "value": "yes" },
    { "name": "ZIP", "value": "02134" }
  ],
  "notes": "Line one\nLine two"
}

Output with the default settings (2 spaces, quote only when needed, YAML 1.1 safe):

name: web
image: nginx:1.27
ports:
  - containerPort: 80
env:
  - name: FEATURE_FLAG
    value: "yes"
  - name: ZIP
    value: "02134"
notes: |-
  Line one
  Line two

Notice three things. nginx:1.27 stays unquoted because a colon not followed by a space is safe. "yes" and "02134" are quoted, otherwise a YAML 1.1 parser would read a boolean and a number, and a Kubernetes env value must be a string. The string containing a line break becomes a |- block: the dash means "no trailing newline", matching the original value exactly.

Options explained

  • Indent – 2 spaces is the convention for Kubernetes and Compose files; 4 spaces is common in Python projects. List items are indented under their parent key either way.
  • String quoting – "Only when needed" produces the cleanest output. "Always double quotes" or "Always single quotes" quote every string value, which some teams prefer for consistency. Keys stay unquoted unless they contain special characters.
  • YAML 1.1 safe – YAML 1.2 treats yes, no, on and off as plain strings, but YAML 1.1 parsers such as PyYAML read them as booleans. Leave this on unless you are sure every consumer uses YAML 1.2.
  • Sort keys A–Z – orders the keys of every object alphabetically, handy for comparing two files. Arrays are never reordered.

Limitations

  • The input must be strict JSON: no comments, no trailing commas, double-quoted keys. Use the JSON Formatter to find and fix syntax errors first.
  • Integers larger than 253 lose precision because they pass through JavaScript numbers.
  • The converter never creates anchors (&) or aliases (*): repeated objects are written out in full.
  • Inputs over 5 MB are rejected to keep the page responsive.

Tips

  • Paste the YAML into the YAML to JSON converter to confirm a round trip gives back the same data.
  • Do not hand-edit indentation in the output with tabs: YAML only allows spaces.
  • If a long string looks wrapped in your editor, it is not: the converter never folds lines, so each value stays on one line unless it contained real line breaks.

Frequently Asked Questions

Why are some strings like "yes" or "02134" wrapped in quotes?

Unquoted, YAML parsers would read them as something else: yes/no/on/off are booleans in YAML 1.1 and 02134 could become a number or octal value. Quoting keeps them as the strings they were in your JSON.

Is the YAML output valid for Kubernetes, Docker Compose and GitHub Actions?

Yes. The output is generated by the yaml library, which follows the YAML specification, and it uses block style (indentation and dashes) that every one of those tools accepts. The converter does not check Kubernetes-specific fields, only the syntax.

How are multi-line strings converted?

A JSON string containing \n becomes a YAML literal block scalar (|- followed by the indented lines), which keeps the exact line breaks and is much easier to read than an escaped string.

Can the converter add comments to the YAML?

No. JSON has no comments, so there is nothing to carry over. You can add # comments to the output by hand after converting.

Is my JSON sent to a server?

No. Parsing and conversion run entirely in your browser with JavaScript. Nothing you paste is uploaded or stored.

Can I convert YAML back to JSON?

Yes, use the YAML to JSON converter on this site. A round trip returns the same data, although key order may change if you enable Sort keys.