Comments will not survive.Minifying goes through a full parse and re-print, and a comment is not part of the parsed value — js-yaml has nowhere to put it back. If the document is mostly comments explaining itself, keep the original alongside the minified copy.

YAML Input

Minified YAML

comments dropped
Success
Warning

YAML has no whitespace to strip, so "minify" means something different here

A JSON minifier deletes characters that were never meaningful — spaces, newlines, indentation — and the document means exactly what it meant before. YAML cannot do that: indentation is the syntax, so removing it does not compact the document, it breaks it. What this page does instead is switch every level of the document from YAML's indented block style to its flow style — the {key: value} and [a, b, c] forms that look like JSON — which is a real part of the YAML grammar, not a hack, and collapses naturally onto one line.

The output is produced by js-yaml's own dumper with flowLevel: 0, the same library every other YAML tool on this site already depends on, rather than a hand-rolled string squeeze. That matters because a naive "delete the newlines" approach would silently merge a block scalar (| or >) into the line above it and change what the document says — going through the real parser and the real dumper is what keeps the meaning identical while the shape changes.

Like YAML Formatter, this is a parse-then-print step, so it carries the same limitation: comments do not survive, because a comment was never part of the value the parser handed back. The notice below the tool says so up front rather than leaving it as a surprise in the output.

Numbers that are too large for JavaScript to hold exactly — a 19-digit ICCID, a distributed-system ID — are read from the source text and written back as the same bare digits, not rounded and not turned into a quoted string. See the JSON tools' large-number notes if that distinction matters for your document.

Everything runs in your browser. The document never leaves the page.

Compacting a document

  1. Paste the YAMLThe compact version appears on the right as you type, after a short debounce.
  2. Check the comment noticeIf the source had comments explaining itself, keep a copy of the original — the minified version cannot carry them.
  3. Copy or downloadThe output is valid YAML on its own — paste it directly into a one-line context like an environment variable or a CLI flag.

Flow-style YAML is still YAML, not JSON. An unquoted string with a colon or a leading &/* still needs quoting inside {}, the same as it would in block style — js-yaml handles that quoting for you, which is one more reason to run this through the real dumper rather than collapsing whitespace by hand.

A provisioning block, before and after

The same document two ways — indented block style on the left, the flow-style equivalent this page produces on the right.

Block style → flow styleone document, two shapes
subscriber.yamlblock style
subscriber:
  subscriberId: SUB-1001
  msisdn: "447700900142"
  plan: Unlimited 5G
  roaming: true
minifiedflow style, one line
{subscriber: {subscriberId: SUB-1001, msisdn: '447700900142', plan: Unlimited 5G, roaming: true}}

When you need this

Passing a YAML value through an environment variable

Some tools read their configuration from a single environment variable holding a YAML document — a Kubernetes ConfigMap value, a CI variable, a Docker -e flag. Those contexts want one line, and flow-style YAML is a real, parseable line rather than an escaped block.

Pasting a config snippet into a chat message or a log line

A multi-line block loses its formatting the moment it crosses into a Slack message or a single log entry. The flow-style form reads correctly on one line wherever it lands.

Shrinking a document before a size-limited API call

An API that accepts YAML in a request body sometimes caps the payload size. Flow style removes the indentation overhead a deeply nested document accumulates, without touching a single value.

Comparing two documents structurally rather than visually

Two YAML files that differ only in indentation style or comment placement look different at a glance but mean the same thing. Minifying both first makes an actual value diff easier to see.

What this page does

  • Collapses a YAML document into flow style — {} and [] — on a single line, using js-yaml's own dumper rather than a whitespace strip.
  • A 19-digit ICCID or other oversized integer keeps its exact digits, read from the source text rather than rounded by JavaScript's number type.
  • States plainly, before you paste anything, that comments do not survive the round trip.
  • Runs entirely in your browser — the document is never uploaded.

Questions people actually ask

Is the minified output still valid YAML?

Yes. Flow style — {key: value} and [a, b, c] — is part of the YAML 1.2 specification, not a workaround. Any conforming YAML parser, including js-yaml itself, reads it back to the identical structure.

Why does my output still have some indentation or line breaks?

A block scalar (| for literal, > for folded) preserves its own internal line breaks by definition — that is what the block-scalar indicator means, and collapsing it would change the string's value. Everything else collapses to flow style; a multi-line string inside it is the value, not leftover formatting.

Can I get the comments back?

Not from the minified output — the parse step is where they are lost, the same limitation YAML Formatter has. Keep the original document if the comments matter; js-yaml has no comment-preserving mode to recover them from.

Does this work the same as removing whitespace from JSON?

No, and that is the whole reason this page exists rather than a five-line whitespace strip. JSON's whitespace carries no meaning, so deleting it is safe. YAML's indentation IS the syntax, so this page switches the document's style instead of deleting anything structural.

Related tools

Specifications and references

  • YAML 1.2.2 Specification – Defines flow style as a first-class part of the grammar, not an extension
  • js-yaml – The parser and dumper behind this page and every other YAML tool on this site
  • Kubernetes ConfigMap – One real place a single-line YAML value is the required shape
  • MDN — structured data basics – Background on why re-serialising a parsed value discards anything not part of the value itself