YAML Formatter

Format YAML code for better readability and easier editing

1 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 (>).

推广

API开发平台

快速构建、测试和部署API