Minify YAML to Compact Flow Style
Convert expanded YAML to compact flow style (JSON-like inline notation). Reduce file size and line count while keeping the document valid. Free browser-based YAML minifier.
Detailed Explanation
YAML Minification and Flow Style
YAML supports two main notations: block style (the traditional indented format) and flow style (a compact, JSON-like inline format). Minifying YAML means converting block-style documents into the most compact representation possible.
Block Style vs. Flow Style
Block style uses indentation:
server:
host: localhost
port: 8080
features:
- auth
- logging
Flow style uses braces and brackets:
server: {host: localhost, port: 8080, features: [auth, logging]}
Both representations are semantically identical — they produce the same data structure when parsed.
When to Minify YAML
Minification is less common for YAML than for JSON, but there are valid use cases:
- Embedding in scripts — When YAML is passed as a command-line argument or environment variable
- Network transmission — Reducing payload size for API responses that use YAML
- Log output — Compact representations are easier to scan in log files
- Comparison — Flattening structure makes diff comparisons simpler in some cases
How Minification Works
- Parse the YAML into a native data structure
- Serialize using flow style for all collections (maps become
{}, sequences become[]) - Remove comments (comments cannot be preserved in flow style)
- Strip unnecessary whitespace and blank lines
Important Limitations
- Comments are lost — YAML comments (
#) cannot survive minification because flow style has no standard comment syntax within inline collections - Multi-line strings are collapsed — Literal and folded block scalars are converted to quoted strings
- Anchors and aliases — These are preserved but their visual clarity is reduced
- Readability — The entire purpose of YAML is readability, so minification should only be used when compact size is genuinely needed
Use Case
YAML minification is useful when you need to embed configuration in a single line, such as passing YAML through environment variables in Docker containers, including configuration in shell scripts, or transmitting YAML data in URL parameters. It is also helpful for quick structural comparison of two YAML documents by reducing them to a canonical compact form.