YAML Formatter

Prettify, format, and align raw YAML documents with customizable indentation, syntax coordinate validation, and instant export.

How to Use the YAML Formatter

1

Paste or Upload YAML

Paste raw YAML text into the input pane, drop a .yaml file, or click Sample.

2

Choose Indentation Width

Select 2 spaces (standard), 4 spaces, or enter a custom indentation width from the toolbar dropdown.

3

Prettify & Export

Formatted YAML updates instantly in real time. Click Copy or Download to export your .yaml file.

Tool Options

Indentation Spacing (2/4/Custom)

Standardizes nested YAML mappings with uniform 2-space, 4-space, or custom indentation width.

Syntax Validation & Coordinate Tracking

Parses YAML 1.2 syntax and reports exact line and column coordinates when syntax errors occur.

Instant File Export (.yaml)

Export formatted YAML configurations directly to your local file system as a .yaml file.

Your Data Privacy

Web Tool
Privacy-First Architecture
Most of our web tools process your data entirely in-browser. Where server processing is technically required, payloads are evaluated statelessly in-memory and are never stored, saved, or logged.
REST API
Stateless In-Memory Processing
When you use our API endpoints, your requests are processed strictly in-memory without persistent database storage, disk logging, or data retention.
Want to learn more about how we safeguard your information and infrastructure?
Read our full Privacy Policy for detailed security standards, data retention principles, and compliance guarantees.

What does the YAML Formatter do?

The YAML Formatter & Prettifier on blueutils.com formats, cleans, and standardizes raw YAML (YAML Ain't Markup Language) text. It parses documents against YAML 1.2 specifications, cleans irregular whitespace, aligns key-value pairs, formats nested mappings and sequence arrays, and supports configurable indentation levels (2 spaces, 4 spaces, or custom indentation widths).

Core Concepts

Understanding YAML formatting and hierarchy rules ensures error-free manifests:

  • Strict Space Indentation: Indentation in YAML must strictly use space characters (never tab stops \t). Consistent 2-space or 4-space levels ensure cross-platform compatibility across Kubernetes, Docker Compose, Ansible, and GitHub Actions.
  • Hierarchy Alignment: Normalizes nested dictionaries and lists under standard block mapping notation for clear visual hierarchy.
  • Comment & Quoting Preservation: Preserves code comments and standardizes necessary quotes around strings containing reserved punctuation (:, #, {}, []).
  • Multi-Document Streams: Handles multiple YAML documents within a single stream separated by document start markers (---).

How to use the tool?

  1. Paste or Upload YAML: Paste your YAML configuration, Docker Compose file, or Kubernetes manifest into the Raw YAML Input editor, upload a .yaml file, or click Sample.
  2. Select Indentation: Choose your preferred indentation spacing from the toolbar dropdown (2 Spaces, 4 Spaces, or enter a custom indentation width).
  3. Instant Formatting & Export: The formatted result updates automatically in real time in the Formatted YAML Result pane. Click Copy to copy the formatted text to your clipboard or Download to save your clean output.yaml file.

Related Developer Utilities

If you work with YAML manifests, syntax validation, and data conversions, explore these related tools:

REST API Integration

blueutils.com provides a free REST API endpoint (POST https://blueutils.com/api/yaml/format) to programmatically format and prettify raw YAML documents with custom indentation spacing.

API Request Parameters

Name Type Description Example
rawText / yaml String / Object Raw unformatted YAML payload string or parsed object to format. "version: \"3.8\"\nservices:\n web:\n image: node:18-alpine"
indent Number Indentation spaces per level (default: 2). 2

API Request Payload Examples

cURL (Using Raw String)

curl -X POST https://blueutils.com/api/yaml/format \
  -H "Content-Type: application/json" \
  -d '{
    "rawText": "version: \"3.8\"\nservices:\n  web:\n    image: node:18-alpine",
    "indent": 2
  }'

cURL (Using Direct Object)

curl -X POST https://blueutils.com/api/yaml/format \
  -H "Content-Type: application/json" \
  -d '{
    "yaml": {
      "version": "3.8",
      "services": {
        "web": { "image": "node:18-alpine" }
      }
    },
    "indent": 2
  }'

Python

import requests

url = "https://blueutils.com/api/yaml/format"
payload = {
    "rawText": "version: \"3.8\"\nservices:\n  web:\n    image: node:18-alpine",
    "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": "version: \\"3.8\\"\\nservices:\\n  web:\\n    image: node:18-alpine",
                "indent": 2
            }
            """;

        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://blueutils.com/api/yaml/format"))
            .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 input YAML parsed and formatted successfully. true
message String Success confirmation message. "YAML formatted successfully."
result String Prettified and standardized YAML output string. "version: \"3.8\"\nservices:\n web:\n image: node:18-alpine\n"
data Object / Array Parsed native object/array representation returned when input is valid YAML. {"version":"3.8"}
originalSize Number Byte size of raw input payload in UTF-8. 58
resultSize Number Byte size of formatted YAML output in UTF-8. 64

API Response Payload Examples

Success Response (HTTP 200 OK)

{
  "isValid": true,
  "message": "YAML formatted successfully.",
  "result": "version: \"3.8\"\nservices:\n  web:\n    image: node:18-alpine\n",
  "data": {
    "version": "3.8",
    "services": {
      "web": {
        "image": "node:18-alpine"
      }
    }
  },
  "originalSize": 58,
  "resultSize": 64
}

Validation Failure Response (HTTP 400 Bad Request)

{
  "isValid": false,
  "error": "YAML syntax error (Line 3, Column 1): Unexpected scalar token",
  "details": {
    "line": 3,
    "col": 1
  }
}

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 format YAML?

Integrating the YAML Formatter API into automated code linters, build pipelines, or developer platforms provides practical advantages:

  • Rapid Script Validation: Standardizes indentation and syntax across user-contributed configuration files before repository commit.
  • Optimized Token Efficiency for AI Agents: LLMs often generate misaligned YAML spaces. Invoking the formatter API ensures clean, valid YAML without consuming extra reasoning tokens.
  • Deterministic Accuracy Without Hallucinations: Ensures 100% deterministic AST parsing and indentation rendering without dropping configuration keys.

Native Usage

How to format YAML files locally using code editors, terminal CLI utilities, and programming runtimes without external web services:

Visual Studio Code & JetBrains Shortcuts

  • VS Code (Windows / Linux): Shift + Alt + F (with Red Hat YAML extension installed)
  • VS Code (macOS): Shift + Option + F
  • JetBrains IDEs (IntelliJ, PyCharm, WebStorm): Ctrl + Alt + L (Windows/Linux) or Cmd + Option + L (macOS)
  • Neovim: :lua vim.lsp.buf.format() (with yamlls language server)

Windows (CMD / PowerShell)

# Format YAML using Python standard CLI in PowerShell
python -c "import yaml; print(yaml.dump(yaml.safe_load(open('config.yaml')), indent=2, sort_keys=False))" > formatted.yaml

Linux / Unix (Bash & yq)

# Format YAML using the yq CLI utility
yq eval -P '.' config.yaml > formatted.yaml

# Format directly from standard input pipeline
cat manifest.yaml | yq eval -P '.' - > formatted.yaml

Python

Format YAML using PyYAML in Python:

import yaml

with open('config.yaml', 'r', encoding='utf-8') as f:
    data = yaml.safe_load(f)

formatted = yaml.dump(data, indent=2, sort_keys=False, default_flow_style=False)
print(formatted)

Java

Format YAML using Jackson (YAMLMapper) in Java 17+:

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
import java.io.File;

public class YamlFormatterExample {
    public static void main(String[] args) throws Exception {
        YAMLMapper mapper = new YAMLMapper();
        Object object = mapper.readValue(new File("config.yaml"), Object.class);

        String formatted = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(object);
        System.out.println(formatted);
    }
}

Frequently Asked Questions (FAQ)

Can I use tab characters for indentation in YAML?

No. The official YAML specification strictly forbids tab characters (\t) for indentation because different editors interpret tab widths inconsistently. YAML formatters automatically replace tabs with space indentations.

Does this formatter preserve YAML comments?

Yes. The formatter uses AST-based parsing that retains all line and inline comments (# ...), preserving explanatory annotations in Docker Compose and Kubernetes manifests.

What is the recommended standard indentation for YAML manifests?

Standard practice in the Kubernetes, Docker Compose, and Ansible ecosystems is 2 spaces per indentation level. 4 spaces is also supported for readability in deeply nested documents.

How does the formatter handle multi-document YAML files?

Multi-document YAML streams separated by three dashes (---) and ended by three dots (...) are parsed and formatted sequentially, preserving document boundaries.

Is my YAML data uploaded to any remote server or stored in logs?

No. Formatting occurs directly in your local session with in-memory parsing and zero server logging, ensuring complete security for deployment keys, database secrets, and API tokens.

Rate Limits

UI Limits
100 uses per 15 minutes
Max payload size: 5 MB
API Limits
5 requests per 60 minutes
Max payload size: 256 KB
Need higher API rate limits, increased payload sizes, or custom developer solutions?
Contact our engineering team at support@blueutils.com for custom rate limit increases, higher quota allocations, or tailored enterprise integrations.