YAML Formatter
Format and pretty-print YAML online, or convert YAML to JSON. Re-indents nested mappings and validates structure. 100% client-side, no upload.
How it works
- The tool scans block mappings —
key: valuelines nested by leading-space count — and re-emits them at the indent you choose. - It is a structural subset, not a YAML 1.2 implementation: anchors, aliases, block sequences and multi-document streams are not supported (see the notes above).
- There is no error reporting. Malformed input does not raise a diagnostic, it produces silently wrong output.
- Set Output to JSON to serialise the same parsed structure as JSON — the more reliable path for piping into other tools.
About YAML
YAML is the dominant human-readable data format for Kubernetes manifests, Docker Compose, GitHub Actions, Terraform, Ansible, and most CI and CD systems. Its whitespace-sensitive syntax is both its greatest strength and its most frequent source of mistakes. This tool is a pretty-printer for the block-mapping subset of that format: use it to normalise indentation, and use a real YAML parser whenever you need validation, sequences, anchors, or multi-document streams.
A structural subset, not a full YAML parser
This is a hand-written line scanner built on an indentation stack, not a YAML 1.2 implementation, and knowing that explains every limitation below. It reads block mappings — `key: value` lines nested by leading-space count — and re-emits them with consistent indentation. Plain block sequences are not modelled at all: under a mapping key, a `- item` list is dropped and the key ends up as an empty object, so a list survives only when written inline in flow style, and even then it stays a string.
Scalars are recognised by a small pattern table rather than by schema resolution. Integers and decimals are parsed, `true`/`false`/`null`/`~` are honoured with their capitalised forms, and quoted scalars are unwrapped — but the colon split happens before quote handling, so a quoted value containing a colon is truncated at the first one. Sexagesimal and octal forms such as `0o14` and `1:30` are left as strings.
Anchors, aliases and multi-document streams
Anchors and aliases are not resolved. Because `&anchor` reads as an ordinary scalar and `*alias` as another, an anchor line becomes a string value and the indented block beneath it is reattached at the top level — the structure is genuinely lost, not merely reformatted. The merge key `<<` is treated as a literal key name. Any input relying on anchors to share configuration across trees will not survive.
Multi-document streams fare worse. A `---` or `...` delimiter resets the result object and the indentation stack rather than starting a new document, so only the final document in the stream is retained: two Kubernetes manifests separated by `---` format down to the second one alone. Comments are dropped rather than preserved — full-line comments are skipped, and a trailing comment on a value line becomes part of the string.
Output shape and error reporting
Strings containing a colon, a hash, or a newline are emitted as JSON double-quoted scalars, which is valid YAML but looks foreign next to hand-written config. Selecting the JSON output mode runs `JSON.stringify` over the same parsed structure, and that is the more reliable path for piping into anything that consumes JSON. Numbers are re-emitted in their normalised form, so `007` becomes `7`.
There is no error reporting. The scanner does not throw on malformed input, and the `Validate only` button performs the same lenient parse before reporting success unconditionally — a syntax error surfaces as silently wrong output rather than as a diagnostic. Treat this as a cosmetic normaliser for block-style mappings, and reach for a real YAML parser whenever the document contains sequences, anchors, or multiple documents.
Frequently Asked Questions
How do I format YAML?
Can I convert YAML to JSON at the same time?
Why does my list disappear?
Is my data sent to a server?
Do I need an account or API key?
Can I use these tools offline?
All processing happens in your browser. No uploads, no tracking, no servers. Your API keys, configs, and private payloads stay private — 100% client-side.