YAML Formatter
Format YAML with consistent indentation and spacing.
What is YAML Formatter?
A YAML formatter is a tool that rewrites YAML documents with consistent two-space indentation, normalized spacing around colons and dashes, and trimmed trailing whitespace so the file matches the YAML 1.2 specification and stays readable to humans. The structure of the data does not change, only its presentation.
DevOps engineers reach for a YAML formatter when a Kubernetes manifest fails to apply, a GitHub Actions workflow throws a parse error, or a Helm chart picks up tabs from a copy-paste. Reformatting forces YAML through a parser, so indentation drift and stray tab characters surface as errors before the file ever reaches a cluster or CI runner.
Why use a YAML formatter?
- Catch indentation bugs before CI does. YAML is whitespace-sensitive, and a single misaligned key can break an entire Kubernetes deployment. Formatting forces the parser to walk every node and reports the exact line where structure breaks.
- Eliminate tab characters silently. The YAML spec forbids tabs for indentation. Editors that auto-convert tabs to spaces hide the problem until a
kubectl applyfails with a cryptic mapping error. - Standardize team conventions. Two-space indentation, lowercase booleans, and quoted strings stay consistent across pull requests, which reduces review noise and merge conflicts in shared config repos.
- Normalize anchors and aliases. Reused blocks defined with
&anchorand referenced with*aliasget re-emitted in a stable order so diffs show only intentional changes.
How to use the YAML Formatter
- Paste your YAML into the Input panel.
- Click Format.
- Review the rewritten document in the Output panel. Parser errors appear above the input area with a line reference.
- Click Copy to copy the formatted YAML to your clipboard, then paste it back into your manifest, workflow file, or Helm values file.
YAML formatting rules
The YAML formatter applies the conventions in the YAML 1.2 spec and the rules baked into common linters like yamllint and prettier.
| Rule | Convention | Why |
|---|---|---|
| Indentation | 2 spaces, never tabs | Tabs are invalid for indentation in YAML 1.2 |
| Sequence dashes | Indented under parent key | Matches kubectl and Helm output |
| Booleans | true / false lowercase | Avoids the Norway Problem with yes/no |
| Strings | Quoted only when ambiguous | Keeps diffs minimal |
| Comments | Preserved with single space after # | Linter-friendly |
| Trailing whitespace | Stripped | Prevents noisy git diffs |
| Document end | Single trailing newline | POSIX text file convention |
Examples
Before reformatting, indentation and quoting are inconsistent:
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
labels:
app: web
spec:
replicas: 3
template:
spec:
containers:
- name: web
image: "nginx:1.27"After reformatting, indentation is uniform and excess whitespace is gone:
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
labels:
app: web
spec:
replicas: 3
template:
spec:
containers:
- name: web
image: nginx:1.27Common use cases
- DevOps engineers repairing Kubernetes manifests, Helm values, and ArgoCD application files before
kubectl apply. - Platform teams standardizing GitHub Actions, GitLab CI, and CircleCI pipeline files across dozens of repositories.
- Backend developers cleaning up
docker-compose.ymlandserverless.ymlafter merge conflicts shuffle indentation. - SREs auditing Ansible playbooks and inventory files for tab characters that snuck in from external snippets.
Frequently asked questions
What is the correct indentation for YAML?
YAML 1.2 requires spaces for indentation and disallows tabs. The community standard is two spaces per level, which matches the output of kubectl get -o yaml, Helm, and most linters. Some teams use four spaces for top-level sequences, but two is the convention shipped by yamllint defaults and Prettier.
Why does my YAML break when I paste it?
The most common cause is invisible tab characters from a code editor or chat client. Other causes include unquoted strings that parse as booleans (the Norway Problem with no becoming false), unescaped colons inside values, and mismatched indentation between a parent key and its child sequence. The formatter surfaces all three by failing to parse.
Does this YAML formatter validate the schema?
No. It validates YAML syntax against the YAML 1.2 specification but does not check whether the document is a valid Kubernetes manifest, GitHub Actions workflow, or any other schema. For schema validation, use kubeconform for Kubernetes or action-validator for GitHub Actions.
Is YAML the same as JSON?
Every JSON document is valid YAML, but not the reverse. YAML adds comments, anchors, multi-document streams, and significant whitespace. JSON is stricter and machine-friendlier. Convert between the two when you need YAML’s readability for editing and JSON’s compactness for transport.
How is YAML formatting different from YAML linting?
A formatter rewrites the document to a canonical form. A linter reports problems without rewriting. Tools like yamllint and actionlint enforce stylistic and semantic rules that go beyond what a formatter can do, such as line-length limits or required keys.
Does the formatter preserve comments?
Yes. Inline comments and block comments are preserved in their original position. Empty lines between blocks are also preserved when they appear at logical breaks. Comments inside flow-style collections may be dropped because the YAML spec does not define their position.
Can it handle multi-document YAML files?
Yes. Documents separated by --- are parsed individually and re-emitted with a single --- separator between them. A leading --- on the first document is preserved if present, omitted if not.
Related tools
- SQL Formatter & Beautifier - pretty-print SQL with standard keyword casing and indentation.
- Markdown Formatter - normalize headings, lists, and code blocks across Markdown files.
- TypeScript Formatter - apply Prettier defaults to TypeScript source files.
- JSON to YAML Converter - convert between JSON and YAML in either direction.
Related tools
ShotMark captures what you do here, in one click.
The traces, payloads, and tests you run by hand? ShotMark grabs the whole bug and hands it to your AI agent.