Convert YAML to JSON (and Avoid Indentation Errors)
Since YAML 1.2 every JSON document is valid YAML. Convert YAML config to JSON, and watch for indentation and type-inference traps.
YAML and JSON are related
YAML 1.2 is a strict superset of JSON, so any JSON document is already valid YAML. Converting YAML to JSON mainly means turning indentation-based structure into braces and brackets.
Indentation rules
YAML forbids tab characters for indentation — use spaces, and keep sibling keys at the same depth. A stray tab or a misaligned key is the most common YAML parse error.
The Norway problem
Unquoted NO, yes, on, and off can be read as booleans by some parsers, so the country code NO becomes false. Quote such values to force them to stay strings.
Converting safely
Validate the YAML first, then convert. Quote ambiguous scalars and confirm that numbers, dates, and leading-zero values survive as the type you expect.
Multi-document YAML streams
A single YAML file can hold multiple documents separated by '---'. JSON has no equivalent — convert each document independently and wrap them in a JSON array if a downstream tool needs all of them in one value. Kubernetes manifests are the most common case.
Anchors and aliases
YAML's & anchor and * alias let you reuse a node by reference, but JSON has no aliases. A safe converter resolves each alias to a copy of the anchored value, which expands the document. Be aware that round-tripping back to YAML loses the original sharing.
When YAML loses fidelity
Comments, tag annotations like !!binary, custom tags, the difference between block and flow style, and key order are all dropped when YAML becomes JSON. For pure data interchange that is fine; for human-edited config that gets edited again later, keep the YAML as the source of truth.
See also
This guide handles one format boundary. The hub lists every JSON ↔ neighbor-format conversion with its standard and edge cases.
JSON repair guides
Topic hubs
- JSON Parse Errors: Read the Message, Jump to the Fix
- Fix Invalid JSON: From 'What's Wrong' to a Clean File
- JSON Formatter, Validator, Viewer: Pick the Right Tool
- Repair LLM JSON Output: Handling Almost-JSON from AI
- Privacy: JSON Tools That Don't Leave Your Browser
- JSON Interop: YAML, CSV, XML, JWT, Schema
Specific guides
- How to Decode Base64 Strings (and JWT Payloads)
- URL Encoding: Percent-Encode Query Parameters and Paths
- Convert JSON to CSV: Flatten an Array of Objects
- Convert JSON to XML: Root Elements, Attributes, and Arrays
- Escape JSON as a String Literal (and Decode Double-Encoded JSON)
- Fix Trailing Comma in JSON
- Fix Single Quotes in JSON
- Fix Unquoted Keys in JSON
- Repair LLM JSON Output
- Fix JSON Parse Error: Expected Property Name
- JSON vs JS Object Literal: The Key Differences
- Validate JSON Before API Requests
- JSON Formatter vs JSON Repair
- Fix JSON Unexpected Token Errors
- JSON to JavaScript Object Converter