Free tool

JSON to YAML converter

Paste JSON and get clean, readable YAML as you type, ready for a Kubernetes manifest, a docker-compose.yml or a CI workflow. Strings get quotes only where YAML needs them, and values that older YAML parsers would misread (on, no, 22:22) are quoted for you.

Free · no sign-up · runs in your browser, nothing is uploaded

JSON input
573 B
Drop a .json file here, or click to open one
YAML output

Loading the parser…

What the YAML output looks like

Each JSON construct has one natural YAML form. The converter writes block style (indentation, no brackets) because that is what config files use:

JSONYAMLRule
{"name": "web"}name: webPlain strings need no quotes.
{"port": "8080"}port: "8080"A string that looks like a number keeps quotes, so it stays a string.
{"tags": ["a", "b"]}tags: - a - bArrays become lists, one item per line.
{"run": "a\nb\n"}run: | a bMulti-line strings become readable | blocks.
{"env": {}}env: {}Empty objects and arrays stay in flow style.
{"x": null}x: nullnull stays null.
{"flag": "on"}flag: "on"Quoted when the YAML 1.1 safe option is on (default).

The options, and when to use them

  • Indent 2 or 4 spaces. Two is the convention for Kubernetes, Docker Compose and GitHub Actions. YAML never allows tabs.
  • Quotes only when needed, single or double. Double quotes allow escapes like \n and é; single quotes take text literally, with '' for a single quote inside. Keys are left unquoted where possible.
  • YAML 1.1 safe. YAML 1.2 reads no as the text "no", but YAML 1.1 parsers such as PyYAML read it as false. Keeping this on quotes such values so every parser gets the string you meant. This is how Norway's country code NO turns into false.
  • Indent lists. Off gives the style kubectl get -o yaml prints, with - item at the same column as its key.
  • Sort keys. Alphabetical order makes two files easy to diff. Off keeps the JSON order, which is usually the order people expect to read (apiVersion, kind, metadata, spec).
  • Array → separate documents. A top-level array becomes several YAML documents separated by ---, the format kubectl apply -f accepts for many resources in one file.

Convert JSON to YAML in code

Command line with yq (v4):

yq -p=json config.json > config.yaml
cat config.json | yq -p=json -I=4     # 4-space indent

Python with PyYAML. safe_dump sorts keys unless you pass sort_keys=False:

import json, yaml

with open("config.json", encoding="utf-8") as f:
    data = json.load(f)
print(yaml.safe_dump(data, sort_keys=False, allow_unicode=True))

JavaScript / Node.js with the yaml package:

import { stringify } from 'yaml';

const yaml = stringify(JSON.parse(jsonText), { indent: 2 });

Go with sigs.k8s.io/yaml:

import "sigs.k8s.io/yaml"

y, err := yaml.JSONToYAML(jsonBytes)

Kubernetes can print any live object as YAML directly: kubectl get deployment web -o yaml.

JSON or YAML: which one to use

JSONYAML
CommentsNoYes, with #
StructureBraces, brackets and commasIndentation (spaces only)
StringsAlways in double quotesQuotes optional in most cases
Several documents in one fileNo (JSON Lines is a separate convention)Yes, separated by ---
Reuse a blockNoAnchors (&) and aliases (*)
Typical useAPIs, data exchange, package.jsonConfig: Kubernetes, Compose, CI pipelines

YAML 1.2 was written so that JSON is a subset of it: a YAML 1.2 parser reads JSON as is. To go the other way, use the YAML to JSON converter, and check the result with the YAML validator. If the JSON itself has errors, the JSON formatter shows and repairs them. More tooling for configs and deploys: DevOps tools on DevHunt.

FAQ

How do I convert JSON to YAML?+

Paste the JSON above and the YAML appears as you type. Pick 2 or 4 spaces, the quote style and the list style, then copy it or download converted.yaml. On the command line, yq -p=json file.json prints the same data as YAML.

Why are some strings quoted in the YAML output?+

A string is quoted when, left bare, YAML would read it as something else: "true", "123", "null", "0755", or text starting with characters like #, @, * or a quote. With the YAML 1.1 safe option on, yes, no, on, off and values like "22:22" are quoted too, because older parsers turn them into booleans and numbers.

Does converting JSON to YAML change the data?+

No. The YAML holds the same keys, values and types, in the same order unless you choose to sort keys. Large integers stay exact. Comments in the JSON (if you paste JSONC) are dropped, because they are not data.

Can I add comments to the YAML?+

Yes. After converting, add comments with # anywhere: on their own line or after a value. JSON has no comments, which is one reason people move config files from JSON to YAML.

How do I put several Kubernetes manifests in one YAML file?+

Paste a JSON array of manifests and turn on "Array → separate documents". Each item becomes its own document, separated by ---, and kubectl apply -f file.yaml applies them all.

Should lists be indented under their key?+

Both styles are valid YAML and parse to the same data. Indented lists (key:, then " - item") are the common default; kubectl get -o yaml writes lists at the same indent as the key. Pick whichever your team uses with the Indent lists switch.

Is my JSON uploaded anywhere?+

No. Parsing and conversion happen in your browser. Nothing is sent to a server. Small inputs are kept in the page URL so you can share a result, so do not share links that contain secrets.

Sources: YAML 1.2.2 specification · YAML 1.1 boolean type · RFC 8259 (JSON) · yq: convert JSON and YAML · yaml library: options · PyYAML documentation · Kubernetes: managing resources. Checked October 2026.