YAML Formatter
Format YAML code for better readability and easier editing
Format Settings
Format Options
Usage Instructions
Enter YAML Code
Paste or type your YAML code in the text area
Set Format Options
Choose whether to expand complex values, preserve comments, sort keys, and set indentation size
Format or Minify
Click "Format YAML" to beautify the code, or click "Minify YAML" to reduce spaces and line breaks
Get Result
After formatting is complete, you can copy the code or download it as a YAML file
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
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
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
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]
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
Anchors and References
Using anchors (&) and references (*) allows reusing data to avoid duplicate definitions.
Merge Keys
Using merge keys (<<) allows merging the contents of one mapping into another.
Multiline Strings
YAML provides multiple ways to handle multiline strings, including preserving line breaks (|) and folding line breaks (>).
推荐工具
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.
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.
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.
HTML to Markdown Tool - Online Toolbox
Free Online HTML to Markdown Tool. It helps you convert HTML code to Markdown format, improving content processing efficiency.