What is the difference between YAML and JSON?
YAML: It 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.
The most common data types used in YAML are :
- Numbers
- Strings
- Null values
- Boolean
- Dates and timestamps
- Sequences
- Nested values
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: It 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.
Some of the valid data types used in JSON are:
- Numbers
- Strings
- Objects
- Arrays
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 are:
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. |
Please Login to comment...