Skip to content

YAML Formatter & Validator

Formatted YAML

Loading parser…

Estimates for educational purposes — not financial, medical, or legal advice. See terms.

YAML is the dominant configuration language for modern DevOps tooling — Kubernetes, GitHub Actions, Docker Compose, Ansible, Helm, GitLab CI, OpenAPI. Reading a 200-line manifest with broken indentation is the exact moment you need a tool like this.

How parsing works

The input is parsed by js-yaml’s loadAll (multi-document aware) into a JavaScript value tree. Format re-emits with dump; To JSON serialises with JSON.stringify. Validate parses and summarises without re-emitting. js-yaml uses YAML 1.2 with the JSON_SCHEMA, which restricts type coercion to the safe subset (strings, numbers, booleans, null, arrays, objects).

The parser is dynamic-imported on first interaction, so the initial page load is fast even though js-yaml itself is ~25 KB. The first format or validate carries a ~50ms delay; everything after that is instant.

Example: cleaning up a docker-compose file

Input (broken indentation):

version: '3'
services:
   web:
    image: nginx
    ports:
        - "80:80"
   db:
    image: postgres

Format:

version: '3'
services:
  web:
    image: nginx
    ports:
      - 80:80
  db:
    image: postgres

Consistent 2-space indent, normalised quote-stripping for unambiguous values.

Example: validating a Kubernetes manifest

Paste the manifest, hit Validate. A clean parse produces Valid YAML — 1 document (or N documents for multi-resource files). A bad indent inside a metadata.labels block produces an error like bad indentation of a mapping entry at line 8, column 5 — points you straight at the problem.

Example: converting to JSON

Some tools (jq, Stripe CLI, anything that consumes JSON natively) need JSON, not YAML. Paste the YAML, switch to To JSON mode, copy. A two-line config like:

service: api
port: 8080

becomes:

{
  "service": "api",
  "port": 8080
}

Round-tripping is lossless for any structure that uses only JSON-compatible types — most YAML in the wild qualifies.

Common YAML mistakes

Mixed tabs and spaces. YAML mandates spaces. A single tab anywhere in the file produces a hard parse error in most parsers (and worse, sometimes a silent type confusion). The validator here will reject mixed indentation.

Unquoted boolean-shaped strings. Country code NO, version Yes, postal code Off — under YAML 1.1 these parse as booleans. The JSON_SCHEMA used here treats them as strings, but if you’re consuming the output with a different YAML library, quote them defensively: code: 'NO'.

Tabs in inline arrays. [a,\tb] (where \t is a tab) is malformed. Use spaces inside flow-style structures.

Multi-line strings without folded / literal indicators. A bare multi-line value adjacent to a : is interpreted differently from > (folded) or | (literal). If your value contains newlines or trailing whitespace that matters, use the explicit indicator.

What this tool does not do

It doesn’t preserve comments. js-yaml drops them on parse. For round-tripping with comments intact, use ruamel.yaml or another comment-preserving parser.

It doesn’t support YAML 1.1 type coercions (Yes/No/On/Off as booleans). JSON_SCHEMA is the safer default for modern config.

It doesn’t validate against a schema. For schema validation (JSON Schema, OpenAPI, Kubernetes API), use a dedicated validator with the schema loaded.

It doesn’t resolve anchors and aliases across documents. Within a single document, anchors (&name) and aliases (*name) work; cross-document references aren’t a YAML feature anyway. To translate to or from JSON while keeping the formatting discipline, the YAML ↔ JSON converter is the companion.

Frequently asked questions

Why does it take a moment on first interaction?

Because the YAML parser (js-yaml, ~25 KB gzipped) is loaded only when you actually paste something — not on initial page load. This keeps the page itself light for visitors who only read the documentation. After the first parse, it's cached for the rest of your session and every subsequent format/validate is instant. Trade-off: ~50ms one-time delay for a faster initial page paint and better SEO.

Why YAML over JSON?

YAML is more readable when humans write it: comments are supported, strings rarely need quoting, indentation is meaningful so you can see structure at a glance. The trade-offs are subtle parsing rules (the famous 'Norway problem' where the country code `NO` parses as a boolean false in YAML 1.1, fixed in 1.2 and the JSON_SCHEMA used here), whitespace sensitivity (mixing tabs and spaces breaks things silently), and ambiguous types (`yes` and `no` get parsed as booleans by default). Use YAML for human-edited config (Kubernetes manifests, GitHub Actions, docker-compose); use JSON for machine-to-machine.

Does it preserve comments when formatting?

No. js-yaml drops comments during parse — they're metadata the parser doesn't preserve in the AST it builds. So `# important context` will disappear when you Format. If preserving comments matters (e.g. for round-tripping a Kubernetes manifest with annotations), use a comment-preserving parser like ruamel.yaml in Python or `yaml-language-server`'s parser server-side. For one-off cleanup that doesn't have to round-trip, this tool is fine.

What's the JSON_SCHEMA the tool uses?

js-yaml's JSON_SCHEMA restricts type coercion to the JSON-compatible types: strings, numbers, booleans, null, arrays, objects. The default YAML 1.1 schema would also coerce `Yes`, `No`, `On`, `Off`, `True`, `False` to booleans (which causes the 'Norway problem'). Using JSON_SCHEMA means `'NO'` stays a string, which is almost always what you want. The downside: types like binary blobs (`!!binary`), timestamps (`!!timestamp`), and merge keys (`<<:`) are ignored. For YAML 1.2 strict-mode, this is exactly the right behavior.

What if I have multi-document YAML (--- separators)?

All three modes handle multi-document streams. Format re-emits each document separated by `---`. Validate reports `Valid YAML — N documents`. To JSON wraps the documents in a JSON array. This is the standard way Kubernetes deploys multiple resources from a single file, and the tool round-trips that pattern cleanly.