Minify YAML
Remove comments and unnecessary whitespace from YAML while keeping it valid
Paste bloated YAML — full of stale comments, blank lines, and 4-space indents nobody asked for — and get a compact, valid version back in one click. The parser strips what isn’t data and rewrites the rest at your chosen indent level, often cutting file size by 40-60%.
And everything runs in your browser. Nothing gets uploaded.
How It Works
The tool feeds your YAML through the js-yaml parser, which builds a proper JavaScript object from it. Comments and whitespace don’t survive parsing — they’re not part of YAML’s data model. Then it serializes the object back to YAML with your chosen indent level. The result is structurally identical to the original, just without the fluff.
Examples
Cleaning up a Docker Compose file
Someone left comments on every line during code review. Time to ship.
# Main web service
services:
web:
# Use latest nginx
image: nginx:latest
ports:
- "80:80" # HTTP
- "443:443" # HTTPS
# Mount config
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
services:
web:
image: nginx:latest
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
Shrinking a CI pipeline config
A GitHub Actions workflow with generous spacing and TODO comments cluttering the diff.
name: CI
on:
push:
branches:
- main
# TODO: add caching
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install
run: npm install
- name: Test
run: npm test
name: CI
"on":
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install
run: npm install
- name: Test
run: npm test
Compact mode for an API response mock
You need YAML test fixtures as small as possible so they don’t bloat your test files.
user:
id: 42
name: Jane Doe
email: [email protected]
roles:
- admin
- editor
settings:
theme: dark
notifications: true
{user: {id: 42, name: Jane Doe, email: [email protected], roles: [admin, editor], settings: {theme: dark, notifications: true}}}
Who Uses This
Trim Kubernetes manifests and Helm charts before deploying to keep image layers small.
Clean up Spring Boot or Rails config files that have accumulated stale comments over months.
Strip TODO comments and whitespace from pipeline configs before merging to main.
Compact YAML fixtures and test data files that get loaded into automated test suites.
Common Mistakes
YAML comments aren’t part of the data model. When the parser builds an object from your file, comments vanish — there’s no way to keep them. If you need those notes, save a copy of the original first.
Compact (0-indent) mode dumps everything in flow style — curly braces and brackets on one line. Great for flat structures, but a 10-level-deep Kubernetes spec becomes unreadable. Stick with 2-space indent for complex files.
The parser resolves anchors (&name) and aliases (*name) into their actual values. Your output won’t have those references anymore — it’ll have duplicate data instead. If you rely on anchors to keep your config DRY, minifying will expand them.
Technical Details
- Processing: 100% client-side — nothing uploaded
- Parser: js-yaml library (YAML 1.2 spec)
- Indent Options: Compact (flow), 1-space, 2-space
- Multi-document: Supports files with multiple --- separated docs
- Browser Support: Chrome, Firefox, Safari, Edge
Frequently Asked Questions
What does minifying YAML actually do?
It strips out comments, blank lines, and extra whitespace. The parser reads your YAML into a data structure, then writes it back with minimal formatting. Your data stays the same — the file just gets smaller.
Is the minified output still valid YAML?
Yes. The tool doesn’t do string manipulation — it fully parses the YAML and re-serializes it. If your input was valid, the output will be too. Any parser that reads YAML 1.2 will handle it fine.
Can I keep my comments when minifying?
No. YAML comments exist only in the text file — they’re not part of the data. Once the parser builds an object, comments are gone for good. If you need them, keep an unminified copy around.
How much smaller will my YAML file get?
Depends on how many comments and blank lines you had. A heavily commented config file can shrink 40-60%. A file that was already clean might only lose 5-10%. The tool shows you exact byte counts and percentage after minifying.
Is my YAML data sent to a server?
Not at all. Everything happens in your browser with JavaScript. Open your network tab if you want proof — you won’t see a single request when you click Minify. Your config files stay on your machine.