How to Convert JSON to YAML
Published 2026-08-10
3 min read
By CoShareX
YAML has replaced JSON as the standard format for configuration files in many DevOps tools, including Docker, Kubernetes, and Ansible. If you have an existing JSON configuration, converting it to YAML makes it easier to read and maintain.
In this guide, we'll explain how to parse JSON and translate its key-value pairs into YAML structure.
Indentation Rules in YAML
YAML uses whitespace indentation instead of braces and quotes to represent structure. When converting:
- Braces (
{}) are removed, and key nesting is defined by matching indentation levels. - JSON arrays are formatted as bulleted lists using hyphens (
-). - Strings don't need to be quoted in YAML unless they contain special characters.
Input JSON:
json
1
2
3
4
{
"name": "CoShareX",
"features": ["beautifier", "validator"]
}Output YAML:
yaml
1
2
3
4
name: CoShareX
features:
- beautifier
- validatorFeatured Tool
JSON to YAML
Convert JSON strings into readable YAML (YAML Ain't Markup Language).
Config Customization
When formatting YAML, you can customize the indentation spacing (usually 2 spaces) to ensure the file is easy to read. Adding comments with # is a great way to document your configuration files after conversion.