YAML Formatter
Format, validate, and minify YAML online. Catches indentation errors, tabs, and syntax mistakes with line-precise feedback.
Why Use YAML Formatter?
YAML is whitespace-sensitive and famously punishing — a single tab character or one space too many breaks the entire parse, often with a useless error message at line 87 of a 200-line file. This formatter uses the spec-compliant js-yaml parser, surfaces errors with line/column precision, calls out tab characters before they bite you, and re-emits clean YAML in the indent style you choose. It also sorts keys deterministically — invaluable for keeping Kubernetes manifests, GitHub Actions workflows, and Helm values diff-friendly across edits. If you've ever spent 20 minutes hunting an invisible whitespace bug, this is the tool you wish you'd opened first.
How to Use YAML Formatter
- Choose Format, Validate, or Minify mode at the top of the toolbar.
- Paste your YAML into the left editor — drop a .yml/.yaml file, click Sample, or type directly. Output appears in real time on the right.
- Customize formatting: indent size (2 or 4 spaces), sort keys alphabetically, and flow-style for short arrays.
- If your YAML is invalid, the tool shows the exact line and column with a clear error message — no more guessing where the missing colon is.
- Click Copy or Download to save the formatted/minified YAML.
Worked Examples
Re-indent a messy CI workflow
name: build
on:
push:
branches:
- main
jobs:
test:
runs-on: ubuntu-latestname: build
on:
push:
branches:
- main
jobs:
test:
runs-on: ubuntu-latestMixed 3- and 4-space indents normalized to consistent 2-space indentation.
Validate Kubernetes manifest with bad indentation
apiVersion: v1
kind: Pod
metadata:
name: web
spec:
containers:
- name: nginx
image: nginx:latest❌ bad indentation of a mapping entry (line 8, col 13)
The Validate mode tells you exactly where the indent jump is — kubectl would just refuse to apply with no line number.
Minify a config for an environment variable
host: localhost port: 5432 user: admin options: ssl: true pool: 10
{host: localhost, port: 5432, user: admin, options: {ssl: true, pool: 10}}Useful for embedding YAML in a single-line env var or a JSON-style API payload.
About YAML Formatter
A YAML formatter normalizes indentation, sorts keys (optionally), and re-emits a YAML document so it parses cleanly and is easy to diff. The DevPik YAML Formatter is built on top of js-yaml — the same parser used by ESLint, GitHub Actions tooling, and most Node.js YAML pipelines — so what passes here will pass in your CI. The Format mode reformats your YAML with consistent indentation (2 or 4 spaces), optional alphabetical key sorting (great for stabilizing diffs in Kubernetes manifests), and optional flow-style for short arrays. The Validate mode reports YAML 1.2 compliance — green banner if it parses, red banner with the exact line and column if it doesn't, plus a special warning for tab characters (YAML's most common gotcha — tabs are forbidden for indentation). The Minify mode collapses your YAML into a compact flow-style form, useful for embedding YAML in environment variables or single-line configuration. Multi-document YAML (---separators) is fully supported. Everything runs in your browser; nothing is sent to any server.
Troubleshooting & Common Issues
I get 'bad indentation of a mapping entry' but the indentation looks fine
It's almost always a tab character mixed in with spaces. The tool flags the first line containing a tab in an amber banner above the editor. Open the file in an editor with 'show invisibles' turned on and replace every tab with spaces. YAML 1.2 forbids tabs as indentation entirely.
The string 'yes' becomes true after formatting
YAML 1.1 (the spec js-yaml followed before v4) auto-converts yes/no/on/off/y/n into booleans — the so-called 'Norway problem' (the country code NO became false). YAML 1.2 (which this tool uses) only treats true/false as booleans. If you really need the literal string, quote it: `country: "NO"`.
My multi-line string lost its line breaks
Use a block scalar indicator: `|` preserves line breaks, `>` folds them into spaces. Both can be followed by `-` (strip trailing newline) or `+` (keep all trailing newlines). Without an indicator, YAML treats your multi-line content as a single flowed string.
Sorting keys broke my YAML — order matters here
Some YAML consumers (notably Helm chart values overriding upstream defaults, and OpenAPI specs where path ordering affects rendering) care about key order. Disable 'Sort keys' for those files and only enable it for content where order is purely cosmetic (Kubernetes objects, GitHub Actions workflow steps within a job).
Frequently Asked Questions
What is the difference between YAML and JSON?
Both represent the same data shapes (objects, arrays, strings, numbers, booleans, null), but YAML adds whitespace-sensitive indentation, comments (#), multi-line strings, anchors and aliases (&, *), and is a strict superset of JSON — every valid JSON document is also valid YAML. JSON is easier for machines to parse quickly; YAML is easier for humans to read and edit, which is why it dominates in CI configs, Kubernetes manifests, and configuration files.
Can YAML use tabs for indentation?
No. The YAML 1.2 spec forbids tabs as indentation. You can use tabs inside string values, but not for the indentation that defines structure. This tool flags any tab in an indentation position with an amber warning. Most editors can be configured to insert spaces when you press Tab — turn that on for any file ending in .yml or .yaml.
How do I validate YAML syntax?
Switch to Validate mode in this tool, paste your YAML, and you'll see either a green 'Valid YAML' banner or a red error with the exact line and column number. Under the hood it uses js-yaml (a YAML 1.2 compliant parser). For scripting validation in CI, install js-yaml from npm and call `yaml.loadAll(content)` — it throws YAMLException with a `mark.line` property on errors.
Why does my YAML number become a string after formatting?
If a 'number' starts with a leading zero, contains a colon, or is wrapped in quotes, YAML treats it as a string. Common gotcha: ZIP code 02134 — without quotes, YAML parses it as octal 02134 = decimal 1116. Always quote identifier-like strings: `zip: "02134"`.
Does this YAML formatter support multi-document files?
Yes. YAML uses `---` to separate documents, and the formatter reads all documents with `loadAll`, formats each, and joins them back together. This works for kubectl manifests where one file holds multiple Kubernetes objects, and for Bitbucket Pipelines configs that allow multiple documents.
Is my YAML data sent to a server?
No. The entire formatter runs in your browser using js-yaml bundled with the page. Nothing leaves your machine — paste production secrets if you need to. We have no analytics on the YAML content itself, only anonymous tool-usage counts.
What's the difference between block style and flow style?
Block style uses indentation: `items:\n - a\n - b`. Flow style uses brackets, like JSON: `items: [a, b]`. Both parse to the same structure. Block style is more readable for nested data; flow style is more compact for short, primitive arrays. The 'Flow short arrays' option mixes the two — short primitive arrays become flow, everything else stays block.
Should I use YAML or JSON for my config files?
YAML if humans will edit the file (CI configs, Kubernetes manifests, app config). JSON if machines will read/write it heavily and you want to avoid YAML's footguns (tabs, the Norway problem, ambiguous unquoted strings). Many tools accept both; if so, JSON is the safer default for files you generate programmatically.
Related Tools
JSON to YAML Converter
Convert JSON to YAML and YAML to JSON online. Bidirectional converter with indent options, inline arrays, and instant download.
JSON Formatter
Format, beautify, validate and convert JSON data with syntax highlighting, tree view, and auto-fix.
XML to JSON Converter
Convert XML to JSON and JSON to XML online. Bidirectional converter with attribute handling, array detection, and file download.
JSON Schema Generator
Generate JSON Schema from any JSON data. Auto-detects types, formats, required fields, and supports Draft 2020-12 and Draft-07.
Was this tool helpful?