Minify YAML
Convert block-style YAML to compact inline flow style. Useful for embedding YAML in environment variables, annotations, or single-line config values.
What is YAML Minification?
YAML minification converts block-style YAML - which uses newlines and indentation to
express hierarchy - into flow style, which uses curly braces
for mappings and square brackets [] for sequences, similar
to JSON. The resulting output is significantly more compact while representing exactly the
same data structure.
Flow style is defined in the YAML 1.2 specification as a fully supported alternative to
block style. Every conforming YAML parser (including Kubernetes, GitHub Actions, and
Python's PyYAML) handles flow-style YAML identically to
block-style YAML.
Block Style vs. Flow Style
Block Style (Readable)
name: John Doe age: 30 tags: - developer - designer address: city: Anytown zip: "12345"
Flow Style (Compact)
{name: John Doe, age: 30,
tags: [developer, designer],
address: {city: Anytown,
zip: '12345'}} Common Use Cases
Environment Variables
Shell environment variables must be single-line strings. If your application reads YAML from an environment variable (a common pattern in Kubernetes-native apps), the YAML must be in flow style to fit within the variable value.
Kubernetes Annotations
Kubernetes annotations are single-line string values. Some operators and tools embed YAML inside annotation values (e.g., Nginx Ingress controller config snippets). These require compact flow-style YAML.
CI/CD Pipeline Values
When passing YAML as a parameter to a CI/CD pipeline step (GitHub Actions with inputs, Jenkins parameters), compact flow style avoids multi-line string escaping issues.
Size Comparison & Transmission
Flow-style YAML can be 30-50% smaller than the equivalent block-style representation for deeply nested documents, since whitespace and newlines account for a significant portion of block-style file size.
What Is Lost During Minification
- Comments - YAML comments (
# ...) are metadata on the text representation; they do not survive parse-and-reserialise. If your original file has documentation comments, keep the original. - Anchors and aliases - YAML anchor (
&name) and alias (*name) references are resolved to their full values before re-serialisation. The output will be larger if the original used aliases to avoid repetition. - Key ordering - YAML mappings are unordered by definition. The serialiser may re-emit keys in a different order than the original document. Do not rely on key order in YAML.