YAML Formatter

Format YAML code for better readability and easier editing

1015 Uses | 5.0 Rating

Format Settings

Format Options

Usage Instructions

1

Enter YAML Code

Paste or type your YAML code in the text area

2

Set Format Options

Choose whether to expand complex values, preserve comments, sort keys, and set indentation size

3

Format or Minify

Click "Format YAML" to beautify the code, or click "Minify YAML" to reduce spaces and line breaks

4

Get Result

After formatting is complete, you can copy the code or download it as a YAML file

5

Usage Tip

Ensure your input is valid YAML code, otherwise it may not format correctly. For large files, processing may take longer

YAML Basic Knowledge

What is YAML?

YAML (YAML Ain't Markup Language) is a human-friendly data serialization language, commonly used for configuration files and data exchange. It is designed in a concise, readable format, especially suitable for data structures that need manual editing and reading. YAML uses whitespace indentation to represent data hierarchy, instead of using brackets or tags.

YAML Basic Syntax

1

Indentation and Hierarchy

YAML uses whitespace indentation to represent data hierarchy. Tabs are not supported. Usually 2 or 4 spaces are used as indentation units.

# YAML indentation example
example:
  level1:
    level2:
      key: value
2

Key-Value Pairs

YAML's basic data unit is key-value pairs, using a colon followed by a space (: ) to separate keys and values.

# Key-value pair example
name: John Doe
age: 30
title: Software Engineer
3

Lists and Arrays

Use a hyphen followed by a space (- ) to represent list items.

# List example
fruits:
  - Apple
  - Banana
  - Cherry
  - Date

# Inline list
colors: [red, green, blue, yellow]
4

Comments

YAML uses the hash symbol (#) to represent comments. Content from the hash symbol to the end of the line is ignored.

# This is a comment
name: John Doe  # This is also a comment

YAML Supported Data Types

Strings

No quotes needed, but quotes are required if they contain special characters

simple_string: Hello
quoted_string: "Hello, World!"
multiline: |
  Line 1
  Line 2
  Line 3

Numbers

Supports integers, floating-point numbers, scientific notation, etc.

integer: 42
float: 3.14
scientific: 6.022e23

Booleans

Represents true or false

active: true
enabled: false

Null Values

Represents empty or undefined

empty_value: null
another_empty: ~

YAML Advanced Features

1

Anchors and References

Using anchors (&) and references (*) allows reusing data to avoid duplicate definitions.

2

Merge Keys

Using merge keys (<<) allows merging the contents of one mapping into another.

3

Multiline Strings

YAML provides multiple ways to handle multiline strings, including preserving line breaks (|) and folding line breaks (>).

Advertisement

推荐工具

XML Formatter Tool - Free Online XML Code Beautifier and Compressor

Free online XML formatter tool that supports XML code beautification, compression, validation, and other functions, making your XML code more standardized and readable. Provides real-time formatting preview and supports multiple XML formatting options.

XML to JSON - Free Online Conversion Tool

XML to JSON tool can parse and convert XML format strings and JSON format strings, and format the converted strings.

Online JavaScript Formatter and Minifier - Beautify, Optimize, and Obfuscate JS Code

A powerful online JavaScript (JS) formatting and code minification tool. Supports custom indentation (tabs or spaces), code folding/expanding, word wrap, one-click beautification, and efficient compression/obfuscation of JS scripts—helping developers improve code readability, reduce file size, and optimize website performance.

YAML Formatting - Free Online YAML Tool

Free online YAML formatting and beautification tool that supports automatic indentation adjustment, syntax highlighting, and removes extra spaces, making your YAML code clear and easy to read. No installation required, one-click formatting to improve the readability and maintenance efficiency of YAML files!

YAML to JSON Converter - Free Online Toolbox

Online YAML (YML) and JSON format conversion tool that supports mutual conversion between YAML data and JSON data, and also supports validating whether the input YAML format data and JSON format data are correct.