ShotMark
Skip to Content

YAML Formatter

Format YAML with consistent indentation and spacing.

YAML Input
Formatted
Waiting for input

What is YAML Formatter?

A YAML formatter is a tool that rewrites YAML documents with consistent two-space indentation, normalized spacing around colons and dashes, and trimmed trailing whitespace so the file matches the YAML 1.2 specification and stays readable to humans. The structure of the data does not change, only its presentation.

DevOps engineers reach for a YAML formatter when a Kubernetes manifest fails to apply, a GitHub Actions workflow throws a parse error, or a Helm chart picks up tabs from a copy-paste. Reformatting forces YAML through a parser, so indentation drift and stray tab characters surface as errors before the file ever reaches a cluster or CI runner.

Why use a YAML formatter?

  • Catch indentation bugs before CI does. YAML is whitespace-sensitive, and a single misaligned key can break an entire Kubernetes deployment. Formatting forces the parser to walk every node and reports the exact line where structure breaks.
  • Eliminate tab characters silently. The YAML spec forbids tabs for indentation. Editors that auto-convert tabs to spaces hide the problem until a kubectl apply fails with a cryptic mapping error.
  • Standardize team conventions. Two-space indentation, lowercase booleans, and quoted strings stay consistent across pull requests, which reduces review noise and merge conflicts in shared config repos.
  • Normalize anchors and aliases. Reused blocks defined with &anchor and referenced with *alias get re-emitted in a stable order so diffs show only intentional changes.

How to use the YAML Formatter

  1. Paste your YAML into the Input panel.
  2. Click Format.
  3. Review the rewritten document in the Output panel. Parser errors appear above the input area with a line reference.
  4. Click Copy to copy the formatted YAML to your clipboard, then paste it back into your manifest, workflow file, or Helm values file.

YAML formatting rules

The YAML formatter applies the conventions in the YAML 1.2 spec  and the rules baked into common linters like yamllint and prettier.

RuleConventionWhy
Indentation2 spaces, never tabsTabs are invalid for indentation in YAML 1.2
Sequence dashesIndented under parent keyMatches kubectl and Helm output
Booleanstrue / false lowercaseAvoids the Norway Problem with yes/no
StringsQuoted only when ambiguousKeeps diffs minimal
CommentsPreserved with single space after #Linter-friendly
Trailing whitespaceStrippedPrevents noisy git diffs
Document endSingle trailing newlinePOSIX text file convention

Examples

Before reformatting, indentation and quoting are inconsistent:

apiVersion: apps/v1 kind: Deployment metadata: name: web labels: app: web spec: replicas: 3 template: spec: containers: - name: web image: "nginx:1.27"

After reformatting, indentation is uniform and excess whitespace is gone:

apiVersion: apps/v1 kind: Deployment metadata: name: web labels: app: web spec: replicas: 3 template: spec: containers: - name: web image: nginx:1.27

Common use cases

  • DevOps engineers repairing Kubernetes manifests, Helm values, and ArgoCD application files before kubectl apply.
  • Platform teams standardizing GitHub Actions, GitLab CI, and CircleCI pipeline files across dozens of repositories.
  • Backend developers cleaning up docker-compose.yml and serverless.yml after merge conflicts shuffle indentation.
  • SREs auditing Ansible playbooks and inventory files for tab characters that snuck in from external snippets.

Frequently asked questions

What is the correct indentation for YAML?

YAML 1.2 requires spaces for indentation and disallows tabs. The community standard is two spaces per level, which matches the output of kubectl get -o yaml, Helm, and most linters. Some teams use four spaces for top-level sequences, but two is the convention shipped by yamllint defaults and Prettier.

Why does my YAML break when I paste it?

The most common cause is invisible tab characters from a code editor or chat client. Other causes include unquoted strings that parse as booleans (the Norway Problem with no becoming false), unescaped colons inside values, and mismatched indentation between a parent key and its child sequence. The formatter surfaces all three by failing to parse.

Does this YAML formatter validate the schema?

No. It validates YAML syntax against the YAML 1.2 specification but does not check whether the document is a valid Kubernetes manifest, GitHub Actions workflow, or any other schema. For schema validation, use kubeconform for Kubernetes or action-validator for GitHub Actions.

Is YAML the same as JSON?

Every JSON document is valid YAML, but not the reverse. YAML adds comments, anchors, multi-document streams, and significant whitespace. JSON is stricter and machine-friendlier. Convert between the two when you need YAML’s readability for editing and JSON’s compactness for transport.

How is YAML formatting different from YAML linting?

A formatter rewrites the document to a canonical form. A linter reports problems without rewriting. Tools like yamllint and actionlint enforce stylistic and semantic rules that go beyond what a formatter can do, such as line-length limits or required keys.

Does the formatter preserve comments?

Yes. Inline comments and block comments are preserved in their original position. Empty lines between blocks are also preserved when they appear at logical breaks. Comments inside flow-style collections may be dropped because the YAML spec does not define their position.

Can it handle multi-document YAML files?

Yes. Documents separated by --- are parsed individually and re-emitted with a single --- separator between them. A leading --- on the first document is preserved if present, omitted if not.

Like this tool?

ShotMark captures what you do here, in one click.

The traces, payloads, and tests you run by hand? ShotMark grabs the whole bug and hands it to your AI agent.

Private beta accessFounding pricing lockNo spam ever