What does the YAML Comments Remover do?
The YAML Comments Remover on blueutils.com strips single-line comment headers, multi-line comment blocks, and trailing inline comments (# ...) from YAML documents while leaving data structures, indentation, lists, and quoted string values completely intact. It optimizes configuration file sizes for production deployments and ensures private developer notes are stripped before shipping manifests to production environments.
Core Concepts
Understanding how YAML comments are parsed and stripped ensures safe configuration processing:
- Full-Line & Inline Comment Stripping: Identifies comment markers outside of quotes and removes comments from both standalone lines and trailing key-value properties.
- Quoted String Hash Protection: Hash symbols (
#) embedded inside single or double-quoted strings (e.g. hex colors#ffffff, anchors, and URLs) are strictly protected and never removed. - Indentation Normalization: Formats clean YAML documents with customizable 2-space or 4-space indentation following comment removal.
How to use the tool?
- Paste or Upload YAML Payload: Paste your commented YAML configuration into the left Raw YAML Input editor, click Upload, or click Sample.
- Select Indentation: Choose your desired indentation spacing (2 Spaces or 4 Spaces) from the top toolbar dropdown.
- Instant Stripping & Export: Comments are removed in real time as you edit or change indentation settings. Click Copy to copy the clean YAML or Download to save your formatted
blueutils-clean.yamlfile.
Related Developer Utilities
If you work with YAML formatting, minification, and configuration cleanup, explore these related tools:
- YAML Minifier: Compress YAML documents and strip excess whitespace.
- YAML Formatter: Prettify and format YAML documents with custom indentation rules.
- YAML Sorter: Alphabetically sort YAML keys recursively for clean Git diffs.
- YAML Syntax Validator: Validate YAML indentation rules and detect syntax errors.
REST API Integration
blueutils.com provides a free REST API endpoint (POST https://blueutils.com/api/yaml/remove-comments) to programmatically strip comments from YAML configurations.
API Request Parameters
| Name | Type | Description | Example |
|---|---|---|---|
rawText / yaml |
String / Object / Array | Raw YAML configuration string containing comments or object. | "# App config\nport: 8080 # default" |
indent |
Number/String | Optional indentation spacing: 2 (default) or 4. |
2 |
API Request Payload Examples
cURL (Using Raw String)
curl -X POST https://blueutils.com/api/yaml/remove-comments \
-H "Content-Type: application/json" \
-d '{
"rawText": "# Production App Config\nserver:\n host: localhost # Bind address\n port: 8080 # Web port\n color: \"#ffffff\"",
"indent": 2
}'cURL (Using Direct Object)
curl -X POST https://blueutils.com/api/yaml/remove-comments \
-H "Content-Type: application/json" \
-d '{
"yaml": {
"server": { "port": 8080, "color": "#ffffff" }
}
}'Python
import requests
url = "https://blueutils.com/api/yaml/remove-comments"
payload = {
"rawText": "# Production App Config\nserver:\n host: localhost # Bind address\n port: 8080 # Web port\n color: \"#ffffff\"",
"indent": 2
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.json())Java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) throws Exception {
String jsonPayload = """
{
"rawText": "# Config\\nserver:\\n port: 8080 # Port\\n color: \\\"#ffffff\\\"",
"indent": 2
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://blueutils.com/api/yaml/remove-comments"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(jsonPayload))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}API Response Parameters
| Name | Type | Description | Example |
|---|---|---|---|
isValid |
Boolean | Indicates whether the stripping succeeded. | true |
message |
String | Confirmation message returned when stripping succeeds. | "Successfully removed 3 comments from YAML document." |
strippedYaml |
String | Clean YAML document with all comments removed. | "server:\n host: localhost\n port: 8080\n color: '#ffffff'" |
data |
Object / Array | Parsed native representation of the YAML document. | {"server":{"port":8080}} |
commentsCount |
Number | Total number of comment lines or inline comments removed. | 3 |
originalSize |
Number | Byte size of raw input payload in UTF-8. | 85 |
resultSize |
Number | Byte size of clean YAML output in UTF-8. | 45 |
error |
String | Summary error description (when isValid is false). |
"Invalid input: YAML payload cannot be empty." |
API Response Payload Examples
Success Response (HTTP 200 OK)
{
"isValid": true,
"message": "Successfully removed 3 comments from YAML document.",
"strippedYaml": "server:\n host: localhost\n port: 8080\n color: '#ffffff'",
"data": {
"server": {
"host": "localhost",
"port": 8080,
"color": "#ffffff"
}
},
"commentsCount": 3,
"originalSize": 85,
"resultSize": 45
}Validation Failure Response (HTTP 400 Bad Request)
{
"isValid": false,
"error": "Invalid input: YAML payload cannot be empty."
}Rate Limit Exceeded Response (HTTP 429 Too Many Requests)
{
"error": "API rate limit exceeded. Please wait or contact support@blueutils.com."
}Why use an API to remove YAML comments?
Integrating the YAML comment stripper API into build pipelines, packaging scripts, and deployment toolchains provides clear advantages:
- Security & Privacy Protection: Automatically strips internal developer notes, todo reminders, and architecture comments before pushing manifests to customer-facing repositories or production clusters.
- Optimized Payload Compression: Minimizes file byte size for Kubernetes ConfigMaps, AWS CloudFormation templates, and serverless bundle deployments.
- Optimized Token Efficiency for AI Agents: AI workflows can strip noisy comment blocks from large YAML configurations prior to LLM processing, reducing prompt token usage.
Native Usage
How to strip comments from YAML files locally in terminal environments:
Windows (CMD / PowerShell)
# Strip YAML comments using Python in PowerShell
python -c "
import yaml
data = yaml.safe_load(open('config.yaml'))
with open('config.clean.yaml', 'w') as f:
yaml.dump(data, f, default_flow_style=False)
print('Comments stripped successfully.')
"Linux / Unix (Bash)
# Strip YAML comments using yq
yq eval '... comments=""' config.yaml > config.clean.yamlPython
Using PyYAML:
import yaml
with open("config.yaml", "r") as f:
data = yaml.safe_load(f)
with open("config.clean.yaml", "w") as f:
yaml.dump(data, f, default_flow_style=False)
print("YAML comments stripped successfully.")Java
Using Jackson YAML:
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import java.io.File;
public class YamlCommentRemoverExample {
public static void main(String[] args) throws Exception {
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
Object data = mapper.readValue(new File("config.yaml"), Object.class);
mapper.writeValue(new File("config.clean.yaml"), data);
System.out.println("YAML comments stripped successfully.");
}
}