YAML Comment Remover

Paste YAML with comments scattered through it and get back the same document with every comment removed, both full-line and trailing, leaving clean, comment-free YAML ready to hand off to a system that doesn't need the annotations. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-22

Overview

Introduction

Comments are great for humans maintaining a config but sometimes unwanted downstream, when generating a minimal artifact for a build pipeline, or when a comment contains outdated context that shouldn't ship with the file. This tool strips every comment out reliably.

Because it works by parsing the document rather than pattern-matching on `#`, it never mistakes a `#` inside a quoted value (a URL fragment, a hex color) for a comment the way a naive text-based approach could.

What Is YAML Comment Remover?

A comment remover that parses YAML into its underlying data structure and re-serializes it. Since comments fall outside YAML's data model entirely, they simply don't exist anymore once the document has been parsed, they're dropped automatically rather than searched for and deleted.

The result is the same data as the input, just without any of the original comment text, and with layout normalized to consistent block-style indentation.

How YAML Comment Remover Works

The input is parsed with a full YAML 1.2 parser, which discards comments as an inherent part of building the document's value (they're whitespace/trivia from the parser's perspective, not data). The resulting value is then re-serialized as block-style YAML at your chosen indent width.

Because this goes through a real parser rather than a text search for `#`, it can't accidentally strip part of a value that happens to contain a `#` character inside a quoted string.

When To Use YAML Comment Remover

Use it when preparing a config for a system or audience that doesn't need (or shouldn't see) the internal comments left by its authors.

It's also useful as a quick way to get a comment-free version of a file for a side-by-side diff against another comment-free version.

Features

Advantages

  • Never mistakes a `#` inside a quoted value for a comment, unlike a naive text-based stripper.
  • Guarantees the output is valid YAML, since it's built from a real parsed value, not text manipulation.
  • Normalizes indentation as a side effect, useful if the commented file was also inconsistently formatted.
  • Runs entirely client-side, so configuration data never leaves your browser.

Limitations

  • The removal is irreversible from this tool's output alone; keep the original file, or run Extract Comments from YAML first, if you need the comment text later.
  • Because it parses and reformats, minor layout details (flow vs. block style, exact original indentation) change even where content didn't, this isn't a surgical "delete just the comment characters" operation.
  • Only the first document in a multi-document (`---`-separated) YAML stream is processed.

Examples

Removing a full-line and a trailing comment

Input

# service config
replicas: 3 # keep this low in staging

Output

replicas: 3

Both comment styles are dropped; only the actual data remains.

Best Practices & Notes

Best Practices

  • Run Extract Comments from YAML first if you want a record of what's being removed before you commit to stripping it.
  • Use this before minifying or distributing a config to an audience that only needs the data, not the authoring notes.
  • Double-check the output's formatting afterward, since the parse-and-reserialize step can also normalize indentation and flow/block style.

Developer Notes

This is functionally identical to the YAML Formatter, `parseYaml` followed by `toBlockYaml`, since dropping comments is already an inherent side effect of that round trip. It's exposed as its own tool because 'I specifically want to remove comments' is a distinct enough intent from 'I want to reformat this' to deserve its own clear entry point, even though the underlying operation is the same.

YAML Comment Remover Use Cases

  • Preparing a config for distribution to an audience that doesn't need internal authoring notes
  • Generating a minimal, comment-free artifact for a build or deployment pipeline
  • Cleaning up a heavily-annotated file before a side-by-side comparison with another version
  • Removing outdated or sensitive commentary before sharing a config externally

Common Mistakes

  • Expecting only the comment characters to be removed with everything else untouched, formatting (indentation, flow vs. block style) can change too, since this goes through a full parse and reserialize.
  • Forgetting to save a copy of the original if the comments contained context you might need later.
  • Assuming a regex-based approach would be equivalent, it wouldn't, since it risks stripping `#` characters that are actually part of quoted values.

Tips

  • Run Extract Comments from YAML on the original file first if you want to keep a text record of what gets removed.
  • Follow up with YAML Minifier if you want the comment-free result as compact as possible.
  • Use YAML Diff to confirm the data itself is unchanged after stripping comments, only the comments and formatting should differ.

References

Frequently Asked Questions