YAML Formatter

Tidy a YAML document, or move it to JSON and back, without leaving the page.

Runs on your deviceDeveloperWorkingNo account needed

What this tool does

YAML Formatter parses your input with js-yaml and writes the result out again from the parsed value. Tidy up is the default and always produces YAML, so a yml file comes back with consistent indentation while a JSON payload comes back rewritten as YAML. The other two settings pin the output format rather than reading a direction from what you paste: YAML → JSON returns JSON even when the input was already JSON, and JSON → YAML returns YAML for a YAML document. Several documents in one file are read together and written back separated by the same --- lines.

Because this is a parse and re-emit rather than a text tidy, everything in the file that is not data is discarded. Comments go first, and that is the one to weigh before pasting a production config: a Kubernetes manifest or a pipeline definition often carries more explanation in # lines than the values themselves are worth. Blank lines between blocks go too, quoting is normalised to whatever the writer prefers, and anchors, aliases and << merge keys are all expanded — a block reused with *defaults comes back written out in full at every use, with the link between the copies gone.

Type resolution is the js-yaml default schema: the YAML 1.2 core types plus the tags it layers on top, timestamps and !!binary among them. Here yes, no, on and off stay strings instead of becoming the booleans that YAML 1.1 readers in older tooling still make of them. Numeric-looking values are read as numbers, so 012 returns as 12 and 3.10 as 3.1, and version strings or account codes need quotes to survive the trip. An unquoted date such as 2020-01-01 becomes a timestamp and is written back in full ISO form, 2020-01-01T00:00:00.000Z, in tidied YAML as well as in JSON.

Parsing and output both happen in this browser tab, and what you paste is not uploaded — which matters because the YAML that needs reformatting is usually a deployment config holding hostnames, bucket names, registry paths and the occasional secret. There is no file picker: you paste text and copy the result, so the ceiling is what your device holds in memory rather than an upload size. A failure empties the output box and reports the parser's own reason with the line and column where it stopped, and a repeated mapping key counts as one of those failures rather than a silent overwrite. One control needs a warning before you reach for it: Sort keys alphabetically currently replaces any value the parser read as a timestamp with an empty mapping, so leave it off for files with unquoted dates.

How to use it

  1. Paste the YAML. Put the contents of your yml file into the input box, or press Load sample. JSON goes in the same box — the parser reads either one.
  2. Pick the conversion. Tidy up rewrites the document as YAML whatever you paste in. YAML → JSON and JSON → YAML fix the output format instead, so the setting decides what comes out; all three accept either notation going in.
  3. Set indentation and line width. Two or four spaces; YAML forbids tab indentation, so tabs are not offered. Wrap long lines at controls where YAML output folds long scalars — raise it towards 400 to keep them on one line. Sort keys alphabetically reorders every mapping at any depth, but do not use it on a document with unquoted dates, because it empties them.
  4. Run it, then copy the output. The summary under the result names the direction taken and counts what came through: documents for a multi-document file, and otherwise top-level keys, list items or a single scalar. A parse failure leaves the output empty and raises a notice naming the line and column.

Processing & privacy

Runs on your device. Your file is processed directly in this browser.

Common use cases

Cleaning up a hand-edited config

Months of small edits leave a compose file or a values file with mixed indentation and inconsistent quoting. One pass makes the whole document uniform.

Reading a config as JSON

Converting to JSON gives you something jq can query, or something to hand to code running where no YAML parser is available.

Turning a captured payload into config

JSON to YAML reshapes an API response into the form a config file wants, which beats retyping nested objects by hand.

Lining up two environments

Sort keys alphabetically puts the staging and production files into the same order first, so the diff afterwards is about values rather than the order somebody happened to type them in — check first that neither file leaves a date unquoted, since the sort discards those.

Finding why a runner rejects a file

A CI job that reports invalid YAML rarely says where. Pasting the file here gives the reason with a position to look at.

Questions

Is my YAML uploaded anywhere?
No. The js-yaml parser is loaded into this page and the whole conversion runs in the tab, so the document is not transmitted or stored. That is worth knowing for deployment files, which tend to carry hostnames and credentials alongside the settings you actually wanted to tidy.
Are my comments preserved?
No, and it is the main reason to keep the original file. The parser yields data, and comments are not data, so every # line and every blank line between blocks is absent from the output. Reformat a copy, or reformat before the comments go in rather than after.
Is Sort keys alphabetically safe on any file?
No — it has a defect today. The sort walks the parsed document treating every object as a plain mapping, so a value js-yaml resolved to a timestamp, an unquoted 2024-05-01 at any depth, is rewritten as an empty {}, and a !!binary value comes back as a mapping of numbered bytes. Quote those values before sorting, or leave the checkbox off; on everything else the reordering is faithful.
Why did yes and no stay strings?
The parser follows the YAML 1.2 core schema, where only true and false are booleans. YAML 1.1 readers, which include several libraries still in wide use, also treat yes, no, on and off as booleans — so the same file can mean two different things in two tools. Quote the value when you mean the word.
Can it handle several documents in one file?
Yes. Documents separated by --- are read together and written back with the same separator, and the summary counts them. Converting a multi-document file to JSON produces a single JSON array holding each document in order.
Why can I not indent with tabs?
YAML does not allow tab characters for indentation, so offering that choice would only produce files the next parser refuses. Two spaces and four spaces are the options.
What happens to anchors and aliases?
They are resolved and expanded. A node defined with &defaults and reused with *defaults is written out in full at each place it was used, so the file grows and a later change has to be made in every copy rather than once.
What happens if a key is repeated?
The parse fails and the line is named. YAML forbids repeating a key inside the same mapping, and quietly keeping the last one would hide a real defect in the file instead of showing it to you.

Related tools