How to use the YAML formatter
- Paste your YAML into the input box, for example a Kubernetes manifest, a Docker Compose file or a CI pipeline.
- Click Validate to check the syntax. Errors are reported with the line and column where the parser stopped.
- Click Format to re-print the document with consistent indentation and quoting.
- Click Convert to JSON to see the same data as JSON.
- Copy the result back into your project.
The tool parses YAML 1.2 using the open-source js-yaml library, entirely in your browser. Your files are not uploaded or stored anywhere, which matters when they contain hostnames, credentials or other secrets.
What is YAML?
YAML ("YAML Ain't Markup Language") is a human-friendly data serialisation format. Instead of brackets and braces it uses indentation to show structure, a dash (-) for list items and key: value pairs for mappings. It also supports comments with #, multi-line strings, and anchors and aliases for reusing values.
Since YAML 1.2, the format is designed as a superset of JSON, so almost any valid JSON document is also valid YAML. That makes it easy to move between the two: YAML is pleasant to write by hand, while JSON is what most APIs and programs exchange.
Because whitespace carries meaning, a single misplaced space can change the structure of a YAML file without producing an error. Validating and re-formatting reveals how the parser actually reads your document, which is often the quickest way to find a subtle bug.
Common YAML errors and how to fix them
Tabs for indentation. YAML forbids tab characters for indentation. Replace them with spaces; most editors can do this automatically.
Inconsistent indentation. Siblings must line up exactly. In this example, image is indented one space too far:
containers:
- name: web
image: nginx:1.27
Align it with name:
containers:
- name: web
image: nginx:1.27
Missing space after the colon. port:8080 is read as a single plain string, not a key with a value. Write port: 8080.
Special characters in unquoted strings. A value that starts with *, &, !, @, { or [, or that contains : or #, needs quotes:
message: "Error: disk full"
pattern: "*.log"
Duplicate keys. A mapping may not contain the same key twice. Some parsers silently keep the last value; the validator flags it so you notice.
Implicit typing: the classic YAML surprise
YAML guesses types for unquoted values. Under the YAML 1.2 core schema, true and false are booleans, null and ~ are null, and things that look like numbers are numbers. Older YAML 1.1 parsers went further and treated yes, no, on and off as booleans, which is how the country code NO for Norway famously turned into false. Different tools still disagree here, so quote anything that must stay a string:
| Unquoted value | Risk | Safe form |
|---|---|---|
version: 1.10 | Becomes the number 1.1 | version: "1.10" |
zip: 01234 | Leading zero may be lost or read as octal | zip: "01234" |
country: NO | Boolean in YAML 1.1 parsers | country: "NO" |
enabled: yes | Boolean in 1.1, string in 1.2 | enabled: true |
Tips and best practices
- Use two spaces per level; it is the most common style in Kubernetes, Ansible and GitHub Actions files.
- Use
|for multi-line text where line breaks matter (scripts, certificates) and>where lines should fold into one paragraph. - Converting to JSON is a reliable way to confirm structure: if a value lands in the wrong object, the JSON output makes it obvious. For round trips, use the JSON ↔ YAML converter.
- Need to tidy the JSON afterwards? The JSON formatter can sort keys and minify it.
Frequently asked questions
Is JSON valid YAML?
For practical purposes, yes. YAML 1.2 was aligned so that JSON documents are valid YAML, which is why you can paste JSON into this tool and it will parse.
Why does YAML not allow tabs?
Tabs render at different widths in different editors, so indentation that looks aligned may not be. The specification forbids tabs for indentation to keep structure unambiguous.
Why did formatting remove my comments?
The formatter parses YAML into data and prints it again. Comments are not data, so they do not survive the round trip. Anchors and aliases are resolved while parsing, so they may come back expanded or with generated names.
Which YAML version does this tool support?
It uses js-yaml, which follows YAML 1.2. Files written for YAML 1.1 parsers usually work, but values such as yes and no are treated as strings.