YAML/JSON Converter
YAML ⇆ JSON Converter
Convert between YAML and JSON formats. Paste your data on either side.
YAML vs JSON Comparison
| Feature | YAML | JSON |
|---|---|---|
| Readability | More human-readable | Compact, less readable |
| Comments | Supports comments (#) | No comments allowed |
| Data Types | Rich (dates, nulls, etc.) | Limited (string, number, etc.) |
| Indentation | Significant (uses spaces) | Not significant |
| Quotes | Optional for strings | Required for strings |
| Use Cases | Config files, K8s, Docker | APIs, data exchange |
YAML Syntax Reference
Scalars
string: Hello World number: 42 float: 3.14 boolean: true null_value: null date: 2024-01-15
Lists
fruits: - apple - banana - orange # Inline colors: [red, green, blue]
Objects
person:
name: John
age: 30
city: NYC
# Inline
point: {x: 10, y: 20}
Multiline Strings
# Literal (preserves newlines) message: | Line 1 Line 2 # Folded (joins lines) text: > This is a long paragraph
How to Use This Tool
- Enter Your Data: Paste YAML content in the left panel or JSON in the right panel. YAML uses indentation for structure; JSON uses braces and brackets. Click "Sample" to load example data.
- Click Convert: Use "YAML to JSON" to convert left to right, or "JSON to YAML" for right to left. The tool parses and transforms the data structure between formats.
- Review the Output: The converted result appears in the opposite panel. Check for structural correctness—YAML anchors and aliases are resolved, JSON produces clean key-value pairs.
- Copy the Result: Click "Copy" to copy the JSON output. Use "Clear All" to reset both panels. The status indicator shows parse success or errors with details.
Technical Details
YAML (YAML Ain't Markup Language) is a human-readable data serialization format using indentation for hierarchy, colons for key-value pairs, and dashes for list items. It supports comments (#), multi-line strings (| and >), and complex features like anchors (&) and aliases (*) for references. YAML is a superset of JSON—valid JSON is valid YAML.
JSON (JavaScript Object Notation) uses explicit syntax: braces {} for objects, brackets [] for arrays, colons for key-value separation, and quotes around strings. It has no comments and strict syntax requirements. YAML to JSON conversion resolves anchors/aliases, strips comments, and adds explicit delimiters. JSON to YAML conversion removes braces/brackets and uses indentation. The data structure itself remains identical—only the serialization format changes.
Common Mistakes to Avoid
- Indentation Errors in YAML: YAML requires consistent indentation (spaces, not tabs). Mixing 2-space and 4-space indentation, or using tabs, causes parse errors. Use a YAML-aware editor that shows whitespace characters.
- Unquoted Special Characters: YAML values starting with *, &, !, |, >, @, or containing colons must be quoted. "key: value: more" fails; "key: 'value: more'" works. Yes/no and true/false are parsed as booleans unless quoted.
- Losing Comments on Conversion: YAML comments (# comment) are lost when converting to JSON, which has no comment syntax. If you convert YAML to JSON and back, comments are permanently gone. Keep original YAML files as source.
Related Tools
Working with tabular data instead of configuration files? Use our CSV/JSON Converter for spreadsheet data. For validating JSON structure and syntax, try the JSON Validator.
Frequently Asked Questions
Is YAML or JSON better for configuration files?
YAML is more readable for humans (comments, no quotes on simple strings, indentation-based). JSON is better for machine-to-machine communication (stricter parsing, broader language support). Use YAML for configs humans edit, JSON for APIs and data exchange.
Why do booleans change format during conversion?
YAML accepts yes/no, on/off, true/false as boolean values. JSON uses only true/false. Converting yes to JSON produces true. Converting back produces true, not yes. The meaning is preserved; the syntax differs.
Can I preserve YAML comments when converting to JSON and back?
No—JSON has no comment syntax. Comments are permanently lost in the YAML to JSON conversion. If you need to round-trip, convert to JSON for a specific purpose, but keep the original YAML file as your source of truth.