YAML Formatter
Validate, format, and convert YAML to JSON
How to YAML Formatter Online
Validate and format YAML, or convert between YAML and JSON.
- Paste your YAML into the input. The parser is YAML 1.2 (modern strict mode).
- Pick an indent width: 2 spaces matches Kubernetes, GitHub Actions, and most modern projects.
- Click Format YAML to canonicalize the document — keys keep their order, but quoting, line widths, and multi-line string forms get normalized.
- Click YAML → JSON to produce a JSON equivalent. Beware: unquoted strings like `yes`, `no`, `1.0` parse as booleans / numbers.
- Click JSON → YAML to go the other direction. Paste valid JSON, get back idiomatic YAML.
- If the input is invalid, the error message includes the line and column from the parser.
- Click Copy to put the output on your clipboard.
About YAML Formatter
YAML ("YAML Ain't Markup Language") is the configuration format that ate the world of DevOps. Kubernetes manifests, GitHub Actions workflows, Ansible playbooks, Docker Compose files, OpenAPI specs, CircleCI configs, and a thousand application YAML config files all use it. The appeal is that it reads like plain text: significant indentation instead of braces, no required quotes around string keys, comments. The pain is that this same flexibility makes YAML the most subtly-tricky-to-parse configuration format in common use. Strings that look like numbers parse as numbers. Strings that look like booleans parse as booleans. Indentation matters, and a single misplaced space changes meaning.
This tool wraps **`js-yaml`** — the JavaScript reference implementation of the YAML 1.2 spec, and the same parser GitHub Actions uses internally to read workflow files. The Format action runs your YAML through `load` → `dump`, which produces the canonical representation that downstream consumers like Kubernetes would also see. That round-trip surfaces a class of bugs immediately: if your original input parses to one thing and the canonical output looks different, you know your spelling was wrong even if it "worked."
The most famous YAML hazard is the **Norway problem**. The country code for Norway is `NO`. YAML 1.1 (the older spec) treats `NO` (case-insensitive) as a boolean false. So this config:
```yaml countries: - NO - SE - DK ```
parsed as `[false, "SE", "DK"]` in YAML 1.1. YAML 1.2 narrowed the boolean set to just `true` and `false`, and `js-yaml` defaults to 1.2, so this specific bug is gone — but the type-coercion table still has `yes`/`no`/`on`/`off` mapping to booleans in older code, and unquoted numbers (`version: 3.10` becomes `3.1`, not `"3.10"`) is still a regular source of bugs. The fix is always the same: quote anything that might be ambiguous.
The **YAML → JSON** conversion is one of the most-used features of any YAML tool. JSON is more constrained — no multi-line strings, no comments, fewer type coercions — which is exactly why application code often prefers it. Convert YAML to JSON and you get a normalized version your downstream code can handle without ambiguity. The reverse direction (JSON → YAML) produces idiomatic YAML output, which is useful when you have programmatic data and want to write a config file a human will edit.
Two things this tool deliberately does not do. **Anchors and aliases** (`&name` / `*name`) get inlined on output with `noRefs: true`. YAML lets you define a value once and reference it elsewhere, but `js-yaml` does not preserve those references through a round-trip — if you need anchor preservation, you need a "round-tripping" parser like Python's `ruamel.yaml`. **Multi-line string spelling** also gets normalized. YAML has `|` (literal blocks, preserving newlines), `>` (folded blocks, joining lines with spaces), and quoted-with-escapes; the dumper picks the form that best fits each string's content rather than preserving your original choice. The semantic content is identical; only the representation changes.
A practical note: **2-space indentation is the only sane default for YAML.** Kubernetes uses 2. GitHub Actions uses 2. Ansible uses 2. OpenAPI uses 2. The tool defaults to 2 because deviating from this in a real project's YAML invariably leads to mixed-indent files that some tools accept and others reject. The 4-space and 6-space options exist for the small set of legacy projects that have committed to those.
Everything runs in your browser. The `js-yaml` library is ~50 KB compressed and is bundled with the tool's chunk. No network requests, no logging. Pasting a Kubernetes manifest with internal hostnames or an Ansible playbook with environment-specific values is safe — nothing leaves your tab.
Related Tools
Frequently Asked Questions
What does the 'Format' button actually do?
It parses your YAML into a JavaScript object, then re-emits it as YAML using `js-yaml`'s dumper. The output uses consistent indentation, a 100-character line width, sensible quoting (only quoting strings that need it), and preserves your key order. It is the same canonicalization step Kubernetes, GitHub Actions, and Ansible all run on YAML they ingest, so the output is what those systems would 'see' regardless of how you typed it.
Why does YAML→JSON sometimes change my values?
YAML has an aggressive type-coercion table. `yes`, `no`, `true`, `false`, `on`, `off` (any case) all become JSON booleans. `null`, `~`, and empty value all become JSON `null`. Unquoted strings that look like numbers become JSON numbers. This is the famous 'Norway problem' — the country code `NO` parses as boolean false. If you need a string, quote it: `country: "NO"`. YAML 1.2 narrowed this, but `js-yaml` defaults to YAML 1.2 behavior, which is the safe modern choice.
Why does my multi-line string get reformatted?
YAML has multiple ways to spell a multi-line string: `|` (literal block, preserves newlines), `>` (folded block, joins lines with spaces), and quoted strings with escape sequences. The dumper picks the form that best matches the string's content and reformats accordingly. The semantic value is preserved exactly — only the representation changes. If you need to preserve a specific spelling, that is a `js-yaml` limitation.
What about YAML anchors and aliases?
Anchors (`&name`) and aliases (`*name`) let you reuse the same value in multiple places. The dumper here is configured with `noRefs: true`, which inlines aliases as full values in the output. This is what Kubernetes-style YAML processors do — anchors are a templating shortcut, not stable data. If you specifically need anchor output, this is the wrong tool; use a YAML round-tripper like `ruamel.yaml`.
Why is YAML→JSON useful?
Because JSON is more constrained and easier for code to handle. YAML's flexibility (multiple string forms, complex types, indentation-as-syntax) makes it pleasant to write but harder to parse. Going through YAML→JSON normalizes your data into the form your application code probably already handles, and the JSON output is portable to languages without good YAML support.
What is the indent width for?
Two spaces is the dominant YAML convention (Kubernetes, GitHub Actions, Ansible, CircleCI, OpenAPI). Four matches some older Python projects. YAML is genuinely flexible — any consistent indent works — but you almost always want to match the project's existing convention. The output applies your chosen indent to every level uniformly.
Is anything sent to a server?
No. Parsing and formatting use `js-yaml` (~50 KB compressed, bundled with the page). All processing is in your browser. Internal Kubernetes manifests, Ansible playbooks, secrets-adjacent configs — all stay local.