Minifies/compresses YAML strings using flow style syntax to remove unnecessary whitespace and newlines, reducing data size for efficient transmission and storage
The YAML Minifier compresses formatted YAML strings by removing unnecessary whitespace, blank lines, and indentation, using YAML flow style syntax (inline mappings with {} and inline sequences with []) to minimize data size while preserving full validity. The compressed YAML retains the exact same data structure and logic, typically reducing file size by 40%-70%.
This tool is particularly useful for optimizing YAML configuration files before deploying to production, in CI/CD pipelines, and when reducing bandwidth for YAML-based API communication. It is the reverse operation of the YAML Formatter — formatting beautifies for readability, minification compacts for efficient transmission and storage.
The core idea behind YAML minification is converting YAML block style (using indentation to represent hierarchy) into flow style (using curly braces {} and square brackets []), fundamentally eliminating the whitespace overhead caused by indentation and line breaks. The YAML specification (yaml.org) formally supports both equivalent representations: block style for human readability, flow style for compactness. This tool leverages the Symfony YAML component to parse input into PHP data structures, then re-serializes using flow style output.
Specific compression strategies include: converting block mappings (key:\n subkey: val) into inline mappings (key: {subkey: val}), converting block sequences (- item1\n- item2) into inline sequences ([item1, item2]), removing all unnecessary indentation whitespace, and normalizing string quoting to the simplest form. While flow style introduces necessary braces, brackets, and commas, the overhead of these structural characters is far smaller than the eliminated indentation spaces and newlines, achieving significant file size reduction overall.
Input (formatted/block-style YAML):
app:
name: AI Tools
debug: true
env: local
url: https://9yun.co
timezone: Asia/Shanghai
database:
default: mysql
connections:
mysql:
host: 127.0.0.1
port: 3306
database: 9yun
username: root
password: "******"
charset: utf8mb4
redis:
host: 127.0.0.1
port: 6379
database: 0
logging:
level: debug
max_files: 30
cache:
driver: redis
prefix: 9yun_
ttl: 3600
Output (minified flow-style YAML):
app: { name: 'AI Tools', debug: true, env: local, url: 'https://9yun.co', timezone: 'Asia/Shanghai' }
database: { default: mysql, connections: { mysql: { host: 127.0.0.1, port: 3306, database: 9yun, username: root, password: '******', charset: utf8mb4 }, redis: { host: 127.0.0.1, port: 6379, database: 0 } } }
logging: { level: debug, max_files: 30 }
cache: { driver: redis, prefix: 9yun_, ttl: 3600 }
YAML Minifier is the reverse operation of YAML Formatter — formatting beautifies for readability, minification compacts for transport. In data processing workflows, it is often used alongside JSON Minifier, JS Minifier, CSS Minifier, and HTML Minifier for comprehensive project resource optimization.