The Wayback Machine - https://web.archive.org/web/20240717032706/https://www.geeksforgeeks.org/what-is-the-difference-between-yaml-and-json/
Open In App

What is the difference between YAML and JSON?

Last Updated : 17 May, 2020
Improve
Suggest changes
Post a comment
Like Article
Like
Save
Share
Report

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.


Similar Reads

Difference between YAML(.yml) and .properties file in Java SpringBoot
These are the files to have different configurations properties required to make the application up and run like to connect with the database what are the credentials, on which port the application will run, etc. YAML (.yml) File: YAML is a configuration language. Languages like Python, Ruby, Java heavily use it for configuring the various properti
3 min read
Difference between package.json and package-lock.json files
In this article, we will learn the major differences between package.json and package.lock.json and their needs in Node. In Node, package.json is a versioning file used to install multiple packages in your project. As you initialize your node application, you will see three files installed in your app that is node_modules, package.json, and package
3 min read
What is difference between JSON.parse() and JSON.stringify() Methods in JavaScript ?
JSON.parse() converts JSON strings to JavaScript objects, while JSON.stringify() converts JavaScript objects to JSON strings. JavaScript utilizes JSON for data interchange between servers and web pages. These methods enable easy data manipulation and transport in web development. JSON.parse() MethodJSON.parse() converts a JSON string to a JavaScrip
2 min read
How to block comments in YAML ?
YAML is a human-friendly data serialization standard for all programming languages. It is commonly used for configuration files and in applications where data is being stored or transmitted. The Normal Way for commenting in YAML is Inline commenting with the "#" symbol, however, if you want to comment blocks then we have a list of ways in which it
2 min read
YAML Comments
Comments are used to prevent the execution of statements. Comments are ignored while the compiler executes the code. Comments are user-friendly as user can get explanations of code using comments. Since you are alright with the sentence structure and fundamentals of YAML, let us continue further into its details. In this part, we will perceive how
3 min read
YAML Full Form
YAML stands for "YAML Ain't Markup Language." It is a human-readable data serialization language used for configuration files and data exchange between languages with different data structures. YAML is often used in programming environments, particularly for configuration files in software applications, and for data exchange in web services. YAML i
3 min read
How to use cURL to Get JSON Data and Decode JSON Data in PHP ?
In this article, we are going to see how to use cURL to Get JSON data and Decode JSON data in PHP. cURL: It stands for Client URL.It is a command line tool for sending and getting files using URL syntax.cURL allows communicating with other servers using HTTP, FTP, Telnet, and more. Approach: We are going to fetch JSON data from one of free website,
2 min read
JSON Modify an Array Value of a JSON Object
The arrays in JSON (JavaScript Object Notation) are similar to arrays in JavaScript. Arrays in JSON can have values of the following types: nullbooleannumberstringarrayobject The arrays in JavaScript can have all these but it can also have other valid JavaScript expressions which are not allowed in JSON. The array value of a JSON object can be modi
2 min read
How to parse JSON object using JSON.stringify() in JavaScript ?
In this article, we will see how to parse a JSON object using the JSON.stringify function. The JSON.stringify() function is used for parsing JSON objects or converting them to strings, in both JavaScript and jQuery. We only need to pass the object as an argument to JSON.stringify() function. Syntax: JSON.stringify(object, replacer, space); Paramete
2 min read
How to transforms JSON object to pretty-printed JSON using Angular Pipe ?
JSON stands for JavaScript Object Notation. It is a format for structuring data. This format is used by different web applications to communicate with each other. In this article, we will see How to use pipe to transform a JSON object to pretty-printed JSON using Angular Pipe. It meaning that it will take a JSON object string and return it pretty-p
3 min read
three90RightbarBannerImg