Share & learn

Through Innovative Digital Library

What is JSON and BSON?

Explain about JSON and BSON. Which one is better JSON or BSON?
 



Answers

Posted by Nikheel on January 2nd 2018 13:56 PM

JSON (Java Script Object Notation) : JSON is an open standard whose main purpose is to exchange data over the web. JSON is in human readable format. JSON uses JavaScript derived syntax for representation of data in human readable format. JSON supports various data structures like arrays and objects. Because of this reason, it becomes very easy to read and data from JSON. JSON is also language independent. The JSON filename has an extension as .json. Where JSON can be used? - Mainly JSON is used while building applications which are based on JavaScript having browser extensions and websites. - We can also use it while serializing structured data and transmitting it over network. - The most important task that JSON does is that of transmission of data between a server and web application. - Web services and APIs use JSON format to provide public data. This example shows how to use JSON to store information regarding novels, based on their name, edition ,etc. Example : An JSON object is a set of key-value pairs which starts with "{" and ends with "}". Lists are one or more values surrounded by [] and separated by ",". { "novel": [ { "id":"101", "name": "AAA", "edition": "first", "author": "John Smith" }, { "id":"107", "name": "BBB, "edition": "second", "author": "E. Jamesworth" } ] } Let's use this JSON with Java Script. Here we will have two objects stored as object1 and object2 out of which we will fetch necessary details of object2 and put it on webpage. Create a file named as test.html and copy following code to it. Once it is saved, run it on any Javascript enabled browser. Output will be as shown in image.

<html>
   <
head>
      <
title>JSON example</title>
        
      <
script language "javascript" >
  
         var 
object1 = { "name" "AAA""author"  "John Smith" };
         
document.write("<h1>JSON Example</h1>");
         
document.write("<br>");
         
document.write("<h3>name = " object1.name+"</h3>");  
         
document.write("<h3>Author = " object1.author+"</h3>");   

         var 
object2 = { "name" "BBB""author"  "E. Jamesworth" };
         
document.write("<br>");
         
document.write("<h3>name = " object2.name+"</h3>");  
         
document.write("<h3>Author = " object2.author+"</h3>");   
  
         
document.write("<hr />");
         
document.write(object2.name " is a good novel to read " ", written by " object2.author);
         
document.write("<hr />");
  
      
</script>
        
   </head>
    
   <body>
   </body>
    
</html>

Posted by Nikheel on January 2nd 2018 13:58 PM

BSON : (Binary JSON) - BSON is basically Binary JavaScript Object Notation. The difference between JSON and BSON is that, BSON isn't in human readable format. - Both JSON, BSON support the embedding of documents and arrays within other documents and arrays. - A single entity from a BSON is called as a 'document'. A document is made of zero or more key-value pairs but in binary format. - MongoDB stores data in BSON format. - It is easy for machines to parse and generate data using BSON. - Like JSON, BSON is also language independent. - The BSON filename has an extension as .bson. Following data types are supported by BSON. e.g. byte, int, double Main characteristics of BSON : 1. Lightweight : BSON is lightweight. Keeping spatial overhead to a base is imperative for any information illustrative arrangement, particularly when utilized over the system. 2. Traversable : BSON is easily traversable. Main purpose of creating BSON was to make traversing fast. 3. Efficient : As almost every language supports basic C data types, it is possible to quickly encode and decode data from BSON. Comparing JSON and BSON : - When it comes to comparing BSON and JSON, BSON has some extra additional features as compared to JSON, like length prefixes. - This is the only reason that BSON needs less space. - If we talk about encoding and decoding BSON is faster than JSON.

Answer Question

Your email address will not be published. Required fields are marked *

  • Minimum 20 character
T1RZ

related questions

Most liked questions

Most answered questions

Login
T1RZ Refresh
Register
T1RZ Refresh
Forgot password
Ask a Question
Minimum 20 character
Minimum 20 character
Reply
Minimum 20 character
T1RZ Refresh