YAML Formatter
Tidy a YAML document, or move it to JSON and back, without leaving the page.
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
- 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.
- 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.
- 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.
- 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?
Are my comments preserved?
Is Sort keys alphabetically safe on any file?
Why did yes and no stay strings?
Can it handle several documents in one file?
Why can I not indent with tabs?
What happens to anchors and aliases?
What happens if a key is repeated?
Related tools
- JSON Formatter — Pretty-print, collapse and inspect JSON instantly.
- Base64 Encoder Decoder — Encode and decode Base64 text and files.
- JWT Decoder — Inspect the header, payload and claims of a JWT.
- Hash Generator — Compute MD5, SHA-1, SHA-256 and SHA-512 digests.
- Regex Tester — Test patterns against sample text with live matches.
- Unix Timestamp Converter — Convert between epoch seconds and readable dates.