InTab

YAML Formatter

Validate and re-indent YAML, keeping comments, with optional key sorting.

Formatters: Pretty-print, minify, validate and compare. It runs in your browser, so nothing you enter is uploaded.

What it does

The YAML Formatter checks that YAML is valid and re-indents it consistently, keeping your comments. It handles files with several documents separated by ---, such as Kubernetes manifests, and can sort keys alphabetically.

How to use it

  1. Paste YAML into Input, or click Sample.
  2. Click Format.
  3. Choose 2 spaces or 4 spaces. YAML does not allow tabs for indentation, so Tab uses 2 spaces.
  4. Tick Sort keys to order keys alphabetically. Sorting rebuilds the document, so comments are dropped when it is on.

Example

app:
    name: InTab   # display name
    debug: false
servers:
    -   host: alpha.local
        port: 8080

Formatted with 2 spaces:

app:
  name: InTab # display name
  debug: false
servers:
  - host: alpha.local
    port: 8080

Good to know

  • An error message gives the reason and position, such as a bad indent or a duplicate key.
  • Indentation is meaningful in YAML. If a key ends up under the wrong parent, the formatter cannot guess what you meant, so check the structure.
  • Common YAML traps: no, yes and on can be read as booleans by older parsers, and 1.10 can become the number 1.1. Quote values like these.

FAQ

Can it convert YAML to JSON? Yes, with the Data Format Converter or the JSON to YAML converter, which works in both directions.

Does it check a Kubernetes or Docker Compose schema? No. It checks YAML syntax only, not whether the fields are right for a particular tool.

More Formatters tools

  • JSON Formatter: Beautify, minify, validate and sort JSON. Handles escaped/stringified JSON.
  • XML Formatter: Beautify, minify and validate XML documents.
  • SQL Formatter: Format SQL for MySQL, PostgreSQL, T-SQL, SQLite and more.
  • Diff Finder: Compare two texts or JSON documents line by line or word by word.
  • Text Diff Checker: Paste two versions of a text and see exactly which words changed.
  • JSON Validator: Check JSON is valid and see the exact line, column and a fix hint when it is not.
  • JavaScript Formatter: Beautify minified or messy JavaScript with your choice of indentation.
  • JavaScript Minifier: Minify JavaScript with Terser: compress, shorten names and see the size saved.
  • HTML Formatter: Indent and tidy HTML, or minify it for production.
  • CSS Formatter: Beautify CSS with one rule per block and consistent indentation.
  • CSS Minifier: Minify CSS with CSSO: remove whitespace, merge rules and shorten values.