The same configuration in two formats
JSON uses braces, brackets and quoted property names. YAML usually uses indentation and fewer punctuation marks. The two formats can represent many of the same object and array structures; JSON has a narrower syntax, whereas YAML includes constructs such as aliases and comments.
app:
name: catalog
replicas: 2
enabled: true
ports:
- 8080
- 8443{
"app": {
"name": "catalog",
"replicas": 2,
"enabled": true,
"ports": [8080, 8443]
}
}Which one should you choose?
Use the format required by the application. JSON is popular for web APIs, machine-to-machine messages and systems that benefit from a strict and predictable grammar. YAML is popular for human-maintained configuration, such as CI jobs and deployment manifests. Readability is a preference, not a guarantee: deep nesting in YAML can be difficult to debug if indentation drifts.
Five things to review after converting
- Numbers and strings.
8080is a number, while"8080"is text. The distinction may matter to the destination application. - Booleans and null. Check whether
true,falseandnullare preserved as values rather than quoted strings. - Comments. JSON has no ordinary comment syntax; comments from YAML are omitted on conversion.
- Aliases and anchors. YAML can refer to repeated values through anchors. A JSON conversion usually expands those references, which may enlarge the output.
- Multiple YAML documents. A YAML stream can contain several documents separated by
---. One JSON document cannot express that stream directly; our converter wraps multiple documents in an array.
How to troubleshoot YAML errors
First verify that indentation uses spaces consistently. If a colon belongs to literal text, quote the value. If a list item is missing a dash or an object key is misaligned, a YAML parser may treat the structure differently than intended. For JSON, check trailing commas and the use of double quotes.
Practical workflow
Paste the sample into the YAML to JSON converter, compare the types in the result, then use the JSON formatter for readability. For the reverse operation, try JSON to YAML. A successful parse only checks syntax; validate application-specific schema separately before production deployment.
Limitations
Our YAML tools use the open-source js-yaml parser in the browser. A standards-compliant YAML file may still be unsuitable for an application's own subset of YAML. Some special types and very large numbers have semantics that cannot be represented identically by ordinary JSON and JavaScript.
Practice with an interactive tool
Use the examples above with our free utilities, right in your browser.
Explore all seven tools →