Difference Between YAML and JSON
YAML and JSON are data serialization formats. YAML is human-readable, uses indentation, supports comments, and is ideal for configuration files. JSON is compact, machine-readable, lacks comment support, and is commonly used in APIs and data exchange.
YAML
YAML is a light-weight, human-readable data-representation language. It is primarily designed to make the format easy to read while including complex features. Since YAML is a superset of JSON, it can parse JSON with a YAML parser.The extensions in YAML are .yaml or .yml. YAML specifications allow user-defined data types as well as explicit data typing.
Example:
Origin:
author: Dan Brown
language: English
publication-date: 2017-10-03
pages: 461
description: | When billionaire researcher Edmond Kirsch is killed,
it is up to Robert Langdon & Ambra Vidal to honor
his memory by making public his findings concerning the
origin of human life and its destiny.
JSON
JSON is a language-independent, human-readable language used for its simplicity and is most commonly used in web based applications.The JSON extensions end with a .json. JSON is a user-friendly substitute to XML as it is light weight and easy to read.
Example:
{
"Origin": {
"author": "Dan Brown",
"language": "English",
"publication-date": "2017-10-03",
"pages": 461,
"description": "When billionaire researcher Edmond Kirsch is killed,
it is up to Robert Langdon and Ambra Vidal to honor
his memory by making public his findings concerning
the origin of human life and its destiny."
}
}
Differences Between YAML and JSON
| YAML | JSON |
|---|---|
| Comments are denoted with a hash/number sign. | Comments are not allowed. |
| Hierarchy is denoted by using double space characters. Tab characters are not allowed. | Objects and Arrays are denoted in braces and brackets. |
| String quotes are optional but it supports single and double quotes. | Strings must be in double quotes. |
| Root node can be any of the valid data types. | Root node must either be an array or an object. |