100% local — your data never leaves your browser

YAML Formatter — Comments and Anchors Survive

Re-indent YAML while what it says stays put. Your comments and anchors come through, so the file is still the one you want to commit.

Instant Private Zero cookies
Indentation

YAML input

YAML output

What this tool does

It re-indents. It does not rewrite.

# Production database — check with on-call before changing
db:
    host: db.example.com   # manual failover
    port: 5432

Two-space indentation, and everything else exactly as you wrote it: the comment above db, the comment after host, the quoting style of each scalar.

The obvious way loses your comments

The obvious way to write a YAML formatter is to parse the file into a value and serialise the value back. It is also wrong, in two ways that leave no trace.

Every comment disappears. A value has no comments; they live in the document, not in the data. A configuration file that someone documented — why this timeout, who to call, what breaks if you change it — comes back silent, and the output is valid YAML, so nothing tells you what was lost.

Anchors are expanded. This:

base: &defaults
  restart: always
  logging: json
web:
  <<: *defaults
worker:
  <<: *defaults

becomes three copies of the same block, longer than the input, with the link between them gone. The next person to change restart has to find all three.

This formatter keeps the document and changes only its layout.

Ambiguous values are left alone

country: NO stays country: NO.

A YAML 1.2 reader sees the string NO; a YAML 1.1 reader — PyYAML — sees the boolean false. Adding quotes would settle that question, and settling it is the author’s call, not a formatter’s: a file written for PyYAML may well have meant false.

The conversion tools do add quotes there, and they are right to: they start from a value they know to be a string. A formatter starts from a file, and a file does not say.

Several documents in one file

--- separates YAML documents, and a file may hold any number of them. Each is formatted in place and the separators stay. That is the shape of most Kubernetes manifests, and it is a stream, not an error.

The options

Indentation — two spaces by default, or whatever you set.

Sort keys — alphabetical, recursively, with each comment following the entry it was attached to. Useful for comparing two files that drifted; leave it off if the order of your keys means something, which in a configuration file it often does.

Private by design

Everything runs locally in your browser with JavaScript. Your data is never uploaded, which makes the tool safe for sensitive content, and it keeps working offline.

Frequently asked questions

Will my comments survive?
Yes — that is the point of this page. A formatter that reads the document into a value and writes the value back **deletes every comment**, and the result is valid YAML, so nothing warns you. This one keeps the document itself and only changes its layout.
What happens to my anchors and merge keys?
They stay as written. `base: &defaults` and `<<: *defaults` come back unchanged, still linked. Expanding them would copy the block into every user, making the file longer than it started and leaving you two places to edit instead of one.
Can I format a file with several documents?
Yes. `---` separates them and each is formatted in place, separators kept. That matters because a Kubernetes manifest is usually exactly that, and it used to be refused outright.

Related converters