By Mian Ali Khalid · Published · How we build and test tools
How to use the yaml minify
- Paste your YAML text into the input area.
- The tool automatically parses the YAML structure as you type or paste.
- View the minified JSON output below the input field.
- Copy the compact JSON for use in APIs, configuration files, or scripts.
How YAML minification works
When you yaml minify a document, the parser reads the indented block structure and translates it into an in-memory tree of mappings, sequences, and scalars. That tree is then serialized as JSON without any extra spaces or line breaks. For example, a YAML mapping like name: Alice followed by age: 30 becomes {"name":"Alice","age":30}.
Comments starting with # are discarded during parsing because JSON has no comment syntax. Block scalars indicated by | preserve newlines, while folded scalars indicated by > replace single newlines with spaces. The result is the most compact valid JSON representation of the original data.
Supported YAML subset
This tool implements a hand-written parser for a practical subset of YAML 1.2. It supports the features most commonly found in configuration files:
- Block mappings (key-value pairs separated by colons)
- Block sequences (items starting with a hyphen and space)
- Flow mappings enclosed in curly braces
{} - Flow sequences enclosed in square brackets
[] - Plain, single-quoted, and double-quoted scalars
- Literal block scalars (
|) and folded block scalars (>) - Comments starting with
# - A single leading
---document marker
Quoted strings and flow collections must fit on one line, and nesting is limited to 200 levels. Input is limited to 2,000,000 characters.
If your document uses advanced features outside this subset, the parser will return a clear error rather than producing incorrect output.
Unsupported features
To guarantee correctness, certain complex YAML features are intentionally not supported. If the parser encounters them, it stops and displays an explicit error message. These unsupported features include:
- Anchors (
&name) and aliases (*name) - Tags (
!!str,!custom) - Merge keys (
<<) - Complex keys written with
? - Multi-document streams separated by
---or...
These features have no direct equivalent in standard JSON, and silently dropping them could change the meaning of your data. If you need to work with these features, consider using a dedicated YAML to JSON converter that handles the full specification.
Why convert YAML to minified JSON
YAML is designed for human readability, relying on indentation and visual structure. However, machines often prefer JSON, and network transfers benefit from smaller payloads. When you compress YAML into minified JSON, you remove all formatting overhead.
Compact JSON drops indentation, comments and line breaks, so the payload is usually smaller, though how much smaller depends on the document. That can matter where configuration payloads are sent frequently or stored in size-limited fields. You can also use tools like JSON formatter if you later need to inspect the minified output in a readable way.
Common edge cases
YAML has many implicit typing rules that differ from JSON. Plain scalars like true, false, null, and unquoted numbers are parsed as their respective JSON types. The strings ~ and empty values are treated as null. Quoted scalars always remain strings, so "true" stays a string rather than becoming a boolean.
Another edge case involves keys. While YAML allows complex keys, this parser expects simple scalar keys. If a key contains special characters, wrap it in quotes. Indent with spaces only: a tab in the indentation is reported as an error, because YAML does not allow tabs there. Scalars follow the YAML 1.2 core schema, so yes, no, on and off stay strings, and integers too large for JavaScript are kept exactly as written.
Worked examples
| Example | Input | Result |
|---|---|---|
| Simple mapping | YAML input: name: Alice / age: 30 | {"name":"Alice","age":30} |
| Nested sequence | YAML input: fruits: / - apple / - banana / - cherry | {"fruits":["apple","banana","cherry"]} |
| Block scalar | YAML input: message: | / Hello / World | {"message":"Hello\nWorld\n"} |
| Flow collections | YAML input: data: {a: 1, b: [2, 3]} | {"data":{"a":1,"b":[2,3]}} |
FAQ
Does this tool upload my YAML to a server?
No. The parsing and minification happen entirely in your browser using JavaScript. Your data never leaves your device.
Why does the output look like JSON instead of YAML?
Minifying YAML directly is difficult because YAML relies on whitespace and indentation for structure. Removing whitespace would break the syntax. Converting to compact JSON is the standard way to achieve the smallest possible representation of the same data.
What happens if I use anchors or aliases?
The parser will stop and show an error stating that anchors and aliases are not supported. This prevents silent data loss or incorrect results.
Are comments preserved in the output?
No. JSON does not support comments, so all YAML comments starting with # are removed during parsing.
Can I use this to check if my YAML is valid?
If the tool successfully produces JSON output, your YAML is valid within the supported subset. For comprehensive validation of the full YAML specification, use a dedicated YAML lint tool.
How are block scalars handled?
Literal block scalars (|) preserve internal newlines. Folded block scalars (>) replace single newlines with spaces. Both are converted into standard JSON strings with escaped newline characters.