Overview
Introduction
Most YAML you encounter is block style, since that's what makes it readable, but block style is also the least compact way to write it. This tool collapses any valid YAML document into flow style, YAML's JSON-like brace-and-bracket syntax, on as few lines as possible.
It's the YAML counterpart to a JSON minifier: same underlying data, far less whitespace, useful whenever you need to embed a small structured value somewhere space is at a premium.
What Is YAML Minifier?
A YAML minifier parses a document and re-serializes it using flow style instead of block style, so `key:\n value` collapses into `{key: value}`.
Unlike JSON minification, which is purely a whitespace change, this is a genuine syntax switch between two forms YAML itself defines. The parsed value is identical either way.
How YAML Minifier Works
Input is parsed with a full YAML parser, then re-serialized with flow style forced on every collection and line folding disabled, so the result lands on the fewest possible lines.
Because it's derived from the parsed value rather than a text-based whitespace stripper, the output is always valid YAML whenever the input was, and it always parses back to the same data.
When To Use YAML Minifier
Use it when you need to pass a small YAML value through something that expects a single line, like an environment variable or a CLI flag.
It's also useful for a quick visual diff of two documents' actual structure, since flow style puts the whole thing in front of you at once instead of spread across many lines.
Often used alongside YAML Formatter & Prettifier and YAML Validator.
Features
Advantages
- Runs entirely client-side, so nothing you paste is uploaded.
- Produces genuinely valid, spec-compliant flow-style YAML rather than a text hack.
- Reports the exact byte savings between the original and minified size.
- Confirms the input is valid YAML as a side effect.
Limitations
- Flow-style YAML is harder to read and edit by hand than block style, so this isn't meant for documents people will maintain directly.
- Comments are not preserved through the parse-and-reserialize round trip.
- Only the first document in a multi-document stream is minified.
- For small, shallow documents, flow-style braces and brackets can occasionally be a few bytes larger than compact block style, since block style needs no delimiters at the top level.
Examples
Best Practices & Notes
Best Practices
- Reserve minified YAML for machine-to-machine contexts, not files people will hand-edit.
- Check the byte-savings stats before deciding it's worth the readability tradeoff for small documents.
- Keep a block-style original if the document has comments you want to keep.
Developer Notes
This calls the `yaml` package's `stringify(value, { flow: true, lineWidth: 0 })`. Setting `flow: true` on the top-level collection propagates flow style to every nested collection as well, and `lineWidth: 0` disables the library's automatic line-wrapping so the result stays on as few lines as possible instead of being folded at a default width.
YAML Minifier Use Cases
- Embedding a small config object in a single-line environment variable
- Shrinking a YAML payload before pasting it into a chat message or ticket
- Producing a compact reference value for a CLI flag
- Quickly comparing two documents' structure at a glance
Common Mistakes
- Minifying a document you intend to keep hand-editing, then losing track of the original readable version.
- Assuming minification removes comments intentionally, when it's actually an unavoidable side effect of reparsing.
Tips
- Pair this with the YAML Formatter to go back to readable block style whenever you need to edit the data again.
- Use the byte-savings numbers to decide whether minifying is even worth it for small documents.