Skip to main content

JSON vs YAML



JSON

JSON(JavaScript Object Notation) is a human-readable data exchange format. 
JSON is built on two structures:
  1. A collection of name/value pairs. In various languages, this is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array.
  2. An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence.
JSON's basic data types are:
Number: a signed decimal number that may contain a fractional part and may use exponential E notation, but cannot include non-numbers such as NaN. The format makes no distinction between integer and floating-point. JavaScript uses a double-precision floating-point format for all its numeric values, but other languages implementing JSON may encode numbers differently.
String: a sequence of zero or more Unicode characters. Strings are delimited with double-quotation marks and support a backslash escaping syntax.
Boolean: either of the values true or false
Array: an ordered list of zero or more values, each of which may be of any type. Arrays use square bracket notation and elements are comma-separated.
Object: an unordered collection of name-value pairs where the names (also called keys) are strings. Since objects are intended to represent associative arrays, it is recommended, though not required, that each key is unique within an object. Objects are delimited with curly brackets and use commas to separate each pair, while within each pair the colon ':' character separates the key or name from its value.
null: An empty value, using the word null

YAML

YAML is a recursive acronym. 
YAML Ain't Markup Language
YAML is a human-friendly data serialization standard for all programming languages. It is commonly used for configuration files, but could be used in many applications where data is being stored (e.g. debugging output) or transmitted (e.g. document headers). Unlike JSON, it has the capability to add comments. 
  • YAML structures enable storage of multiple documents within a single file, usage of references for repeated nodes, and usage of arbitrary nodes as keys.
  • YAML has many additional features lacking in JSON, including comments, extensible data types, relational anchors, strings without quotation marks, and mapping types preserving key order.
  • .yml files begin with '---', marking the start of the document
  • key-value pairs are separated by colon
  • lists begin with a hyphen

JSON vs YAML

Both JSON and YAML aim to be human-readable data interchange formats. However, JSON and YAML have different priorities. JSON’s foremost design goal is simplicity and universality. Thus, JSON is trivial to generate and parse, at the cost of reduced human readability. It also uses a lowest common denominator information model, ensuring any JSON data can be easily processed by every modern programming environment. 
In contrast, YAML’s foremost design goals are human readability and support for serializing arbitrary native data structures. Thus, YAML allows for extremely readable files but is more complex to generate and parse. In addition, YAML ventures beyond the lowest common denominator data types, requiring more complex processing when crossing between different programming environments.
YAML can, therefore, be viewed as a natural superset of JSON, offering improved human readability and a complete information model. This is also the case in practice; every JSON file is also a valid YAML file. This makes it easy to migrate from JSON to YAML if/when the additional features are required.
  • YAML is best suited for the configuration where JSON is better as a serialization format or serving up data for your APIs. This is emphasized by the fact that the JSON doesn't provide the ability to add comments, unlike YAML. YAML is suited for editing files hence writing configuration files is better suited. We should write our configuration files in YAML format where we have the opportunity - it is designed to be readable and editable by humans.
  • JSON ships with a far simpler spec than YAML. JSON can be learned a lot faster than YAML because it is not nearly as robust in its feature set.
  • YAML is a superset of JSON, which means we can parse JSON with a YAML parser.

Comments

Popular posts from this blog

Coin Flipping Puzzle: Interview Question

Golu has 100 identical coins (with head side and tail side) which he wants to donate to someone. There are many people who are aiming to get this collection of 100 coins. So Golu created a puzzle using all 100 coins and declared that the one who will solve his puzzle will get all the coins. You desperately need money so solving the puzzle is only option you have.

The Problem goes like this:
All 100 coins are laying flat on a table. 80 of them are heads up and remaining 20 are tails up. You can’t feel, see or in any other way find out which side is up. Split the coins into two piles(sets) such that there are the same number of tails in each pile.
[Baby Hint]: If number of coins in first pile is n then other pile will have 100-n coins.



First try yourself before peeking into the solution below. 


10 basic git commands you must know

If you work on software development project then you might have already used git for version control. If you haven't used git yet then it's high time you should learn and start using this. Following are the 10 git commands you must know while getting started with git.


1. git init: It initializes the git repository. Running this command creates a directory(.git) inside the current directory which contains git configuration and other repository data.  See below image how there was no git repository initially and after running git init,an empty git repository is initialized as we can see the .git directory gets created.




2. git status: It shows the current status of the repository by showing the difference between index file and the current HEAD commit. It shows the untracked files and files which are added to staging area but not yet committed. You can use different options with git status. 
Using -s option gives the output in short format.
Option -v or --verbose will show the c…

Get access to everyone's Aadhaar data at Rs 500--A Tribune Report

Time and again UDAI(Unique Identification Authority of India) has been asserting that our Aadhaar data is secure and people of India can rest assured about the protection of our personal and biometric data. We have seen security flaws surfacing on the Internet over alleged data breach of Aadhaar and again Tribune has published about the existence of major security breach happening on daily basis. Our Aadhaar data, which is supposed to be highly secure in the hands of UIDAI is available to anyone who can pay Rs. 500.


According to Tribune, people are approached via WhatsApp for the service using which you are provided the portal and the username & password to use the portal. Using this service you can feed Aadhaar number and you will be able to download all personal details. This service is being provided at the mere amount of Rs. 500. Not only this, if you pay Rs. 300 more, you will be able to download the Aadhaar card also.

The government of India is trying to make Aadhaar the so…

10 small business idea to start with in India

If you want to start your own business and you want to start small, here's are 10 business ideas which you can try. The following business takes less capital and more enthusiasm.

1. photography:

If you have a genuine interest in photography and want to make some money out of it then there are many opportunities may land your doorstep. It ney.eds more passion than anything else to start earning from photography. You can sell your photos to stock photography sites like shutterstock.com, Fotolia.com, istockphoto.com, stocksy.com etc. You can also provide your photos to the online travel sites like holidayiq.com. There are many types of photography viz Architectural photography, Candid photography, Documentary photography, Fashion photography, Food photography, Landscape photography, Night-long exposure photography, Conceptual/ fine art photography, wedding photography etc.


2. Wedding Planner:

India is a place of the largest bunch of young people and wedding happens in large number eve…

Alexa can count only from 1 to 10

Alexa is the smart virtual assistance by Amazon. It is beating google now and Siri on non-screen devices. Alexa is hailed for its intelligence but it seems that the Alexa knows to count only from 1 to 10. By 1 to 10, I mean exactly from 1 to 10; neither more nor less. Even asking Alexa to count from 1 to 5 or 3 to 10 or 3 to 5 results in an apology from Alexa. Watch the above video to see for yourself.

BCCI fails to renew domain name for its official website

www.bcci.tv is(or should I use "was") the BCCI's official website where it posts news about Indian cricket and even live-stream the cricket events. I tried to reach to their page and it's rendering above page as the domain has expired and BCCI(Board of Control for Cricket in India) has failed to renew it within the expiry deadline.

After using whois for this domain name, I got to know that the domain was registered on 2nd February 2006 and was updated again today on 4th February 2018.



Will BCCI be able to regain its domain back?

Update: BCCI has got its domain back and showing the contents as earlier.