Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • GfG 160: Daily DSA
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • JS Tutorial
  • JS Exercise
  • JS Interview Questions
  • JS Array
  • JS String
  • JS Object
  • JS Operator
  • JS Date
  • JS Error
  • JS Projects
  • JS Set
  • JS Map
  • JS RegExp
  • JS Math
  • JS Number
  • JS Boolean
  • JS Examples
  • JS Free JS Course
  • JS A to Z Guide
  • JS Formatter
Open In App
Next Article:
Difference Between JSON and BSON
Next article icon

Difference Between JSON and BSON

Last Updated : 24 Jan, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

When working with data in modern web applications, understanding the formats used for data exchange and storage is crucial. Two widely used formats are JSON (JavaScript Object Notation) and BSON (Binary JSON). Although they serve similar functions, they have distinct features and are used in different contexts.

This article will break down the key differences between JSON and BSON, exploring both basic and advanced aspects of each format. By comparing their features, use cases, and performance characteristics, we will highlight when and why to choose one over the other

Differences Between JSON and BSON

Here’s a detailed comparison to help us understand the critical differences between JSON and BSON:

FeatureJSONBSON
Format TypeText-based (human-readable)Binary-based (machine-readable)
ReadabilityYes, easily readable by humansNo, not human-readable
Data Types SupportedStrings, numbers, booleans, arrays, nullAll JSON types + Date, Binary, ObjectId, and others
Space EfficiencyLess efficient for complex data typesMore efficient due to binary encoding
PerformanceSlower parsing and retrievalFaster parsing and retrieval, especially for large data
Use CaseData exchange between client and serverData storage, especially in MongoDB
CompressionNo built-in compressionMore compact due to binary encoding
Support for Large DataJSON may struggle with very large dataBSON supports large documents and binary data natively

Storage Efficiency

While JSON is great for data exchange, BSON excels in storage efficiency due to its binary encoding. BSON is designed to store complex data structures with additional type information, making it better suited for large-scale data operations.

Parsing Speed

Because BSON is in binary format, it can be parsed more quickly than JSON, making it ideal for databases like MongoDB, where speed and efficiency are crucial for reading and writing large amounts of data.

What is JSON ?

JSON (JavaScript Object Notation) is a lightweight, human-readable format for storing and exchanging data. JSON is primarily used to represent data structures such as objects and arrays, making it easy to exchange data between a server and a client (e.g., in web applications). Its simplicity and easy-to-read structure have made it the standard for data interchange across the web.

Advantages of JSON

  • Human-readable: JSON is plain text and easy to understand, making it perfect for debugging and data inspection.
  • Widely Supported: JSON is supported by most modern programming languages, making it a universal data format for APIs, databases, and services.
  • Lightweight: It uses minimal syntax, reducing overhead, and improving data transmission speeds.

JSON Structure Example:

{
"name": "John Doe",
"age": 30,
"isStudent": false,
"courses": ["Math", "Science"]
}

Key Characteristics of JSON:

  • Text-based: JSON files are plain text and can be opened with any text editor.
  • Simplicity: JSON represents data using simple key-value pairs, arrays, and objects.
  • Data Types: JSON supports basic data types such as strings, numbers, booleans, arrays, and null.

What is BSON ?

BSON (Binary JavaScript Object Notation) is a binary-encoded version of JSON, specifically optimized for storing and retrieving data in MongoDB, a popular NoSQL database. BSON extends JSON by adding support for additional data types and providing more efficient encoding for complex data structures. While JSON is primarily used for data interchange, BSON is designed to be more efficient for storage and processing, especially for large and complex datasets.

Advantages of BSON

  • Efficient Storage: BSON’s binary format reduces data size compared to JSON, especially when handling large datasets.
  • Speed: The binary encoding allows for faster reading and writing of data compared to the textual format of JSON.
  • Extended Data Types: BSON supports more advanced data types like Date, Binary, and ObjectId, which are crucial for handling special cases such as timestamps and unique identifiers.

BSON Structure Example

BSON encodes data in a binary format, which is not human-readable. However, the structure is similar to JSON, with additional metadata for each field (such as type and length). For example, a simple document with the same content as the JSON example would be encoded differently in BSON.

Why Use BSON Over JSON?

While JSON is the preferred choice for data interchange due to its simplicity and readability, BSON offers several advantages when it comes to data storage and retrieval. Here are some scenarios where BSON is preferred over JSON:

1. Support for Advanced Data Types

BSON can store additional data types that are not supported by JSON, such as:

  • Date: JSON does not have a native date type, while BSON supports 64-bit integers for dates.
  • Binary Data: BSON can efficiently store binary data (e.g., images, files) using its BinData type.
  • ObjectId: MongoDB uses the ObjectId data type to uniquely identify documents, which is supported in BSON.

2. Faster Data Retrieval

BSON allows faster querying and indexing of data due to its binary format. When dealing with complex or large datasets, BSON’s structure ensures that data is processed and returned quickly.

3. Space Efficiency for Large Datasets

BSON is designed to be space-efficient, particularly when handling large or complex datasets. Its binary encoding minimizes storage requirements, which is important for applications that handle large amounts of data, like databases or real-time applications.

Conclusion

In conclusion, both JSON and BSON serve important roles in data handling but are designed for different purposes. JSON is ideal for lightweight data exchange due to its simplicity and human-readability, making it the standard choice for APIs, web services, and client-server communication. On the other hand, BSON is optimized for efficient data storage and retrieval, particularly in MongoDB, as it supports additional data types like Date, Binary, and ObjectId, and offers faster parsing and better space efficiency.


Next Article
Difference Between JSON and BSON
author
vipinyadav15799
Improve
Article Tags :
  • JavaScript
  • Web Technologies
  • Databases
  • JSON

Similar Reads

    Difference Between JSON and CSV
    JSON: JSON refers to JavaScript Object Notation. 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 for XML as it is lightweight and easy to read.
    2 min read
    Difference Between JSON and XML
    JSON (JavaScript Object Notation) and XML (Extensible Markup Language) are both formats used for structuring and exchanging data. JSON uses Key Value Structure and XML uses Tag based Structure to make platform independent formats. JSON (JavaScript Object Notation) JSON has a straightforward syntax w
    2 min read
    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.YAMLYAML is a light-weight, human-readable data-re
    2 min read
    Difference Between JSON and AJAX
    AJAXAjax is an acronym for Asynchronous Javascript and XML. It is used to communicate with the server without refreshing the web page and thus increasing the user experience and better performance. There are two types of requests synchronous as well as asynchronous. Synchronous requests are the one
    5 min read
    Difference between res.send() and res.json() in Express.js?
    In this article, we will learn about res.send() & res.json(), along with discussing the significant distinction that differentiates between res.send() & res.json(). Let us first understand what is res.send() and res.json() in Express.js? res.send() - The res.send() function is used for sendi
    4 min read
    Interesting facts about JSON
    JSON or JavaScript Object Notation is a lightweight format for transporting and storing data. JSON is used when data is transferred from a server to a web page. This language is also characterized as weakly typed, prototype-based, dynamic, and multi-paradigm. Here are some interesting facts about JS
    2 min read
    How to communicate JSON data between Java and Node.js ?
    So here we will use JSON to communicate between two programs called Java and Node.js. We can use a common text format to communicate, but text format will contain a lot of complexities. However, JSON is lightweight and easy to use. JSON is language-independent and hence can be used by any programmin
    2 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() Method
    2 min read
    JSON Interview Questions
    JSON or JavaScript Object Notationis a lightweight data format used to exchange data between the frontend and backend in web applications. It's very important to revise the important concepts to master JSON and ace interviews.Here we are covering all the important questions starting from basic to ad
    9 min read
    Explain JSON in AJAX
    AJAX is a very popular concept that is used to update the page without reloading the page. AJAX stands for Asynchronous Javascript And XML and because of that many Developers think that AJAX will only use XML to export and import data but that is not true. AJAX can use XML to transport any kind of d
    5 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

'); // $('.spinner-loading-overlay').show(); let script = document.createElement('script'); script.src = 'https://assets.geeksforgeeks.org/v2/editor-prod/static/js/bundle.min.js'; script.defer = true document.head.appendChild(script); script.onload = function() { suggestionModalEditor() //to add editor in suggestion modal if(loginData && loginData.premiumConsent){ personalNoteEditor() //to load editor in personal note } } script.onerror = function() { if($('.editorError').length){ $('.editorError').remove(); } var messageDiv = $('
').text('Editor not loaded due to some issues'); $('#suggestion-section-textarea').append(messageDiv); $('.suggest-bottom-btn').hide(); $('.suggestion-section').hide(); editorLoaded = false; } }); //suggestion modal editor function suggestionModalEditor(){ // editor params const params = { data: undefined, plugins: ["BOLD", "ITALIC", "UNDERLINE", "PREBLOCK"], } // loading editor try { suggestEditorInstance = new GFGEditorWrapper("suggestion-section-textarea", params, { appNode: true }) suggestEditorInstance._createEditor("") $('.spinner-loading-overlay:eq(0)').remove(); editorLoaded = true; } catch (error) { $('.spinner-loading-overlay:eq(0)').remove(); editorLoaded = false; } } //personal note editor function personalNoteEditor(){ // editor params const params = { data: undefined, plugins: ["UNDO", "REDO", "BOLD", "ITALIC", "NUMBERED_LIST", "BULLET_LIST", "TEXTALIGNMENTDROPDOWN"], placeholderText: "Description to be......", } // loading editor try { let notesEditorInstance = new GFGEditorWrapper("pn-editor", params, { appNode: true }) notesEditorInstance._createEditor(loginData&&loginData.user_personal_note?loginData.user_personal_note:"") $('.spinner-loading-overlay:eq(0)').remove(); editorLoaded = true; } catch (error) { $('.spinner-loading-overlay:eq(0)').remove(); editorLoaded = false; } } var lockedCasesHtml = `You can suggest the changes for now and it will be under 'My Suggestions' Tab on Write.

You will be notified via email once the article is available for improvement. Thank you for your valuable feedback!`; var badgesRequiredHtml = `It seems that you do not meet the eligibility criteria to create improvements for this article, as only users who have earned specific badges are permitted to do so.

However, you can still create improvements through the Pick for Improvement section.`; jQuery('.improve-header-sec-child').on('click', function(){ jQuery('.improve-modal--overlay').hide(); $('.improve-modal--suggestion').hide(); jQuery('#suggestion-modal-alert').hide(); }); $('.suggest-change_wrapper, .locked-status--impove-modal .improve-bottom-btn').on('click',function(){ // when suggest changes option is clicked $('.ContentEditable__root').text(""); $('.suggest-bottom-btn').html("Suggest changes"); $('.thank-you-message').css("display","none"); $('.improve-modal--improvement').hide(); $('.improve-modal--suggestion').show(); $('#suggestion-section-textarea').show(); jQuery('#suggestion-modal-alert').hide(); if(suggestEditorInstance !== null){ suggestEditorInstance.setEditorValue(""); } $('.suggestion-section').css('display', 'block'); jQuery('.suggest-bottom-btn').css("display","block"); }); $('.create-improvement_wrapper').on('click',function(){ // when create improvement option clicked then improvement reason will be shown if(loginData && loginData.isLoggedIn) { $('body').append('
'); $('.spinner-loading-overlay').show(); jQuery.ajax({ url: writeApiUrl + 'create-improvement-post/?v=1', type: "POST", contentType: 'application/json; charset=utf-8', dataType: 'json', xhrFields: { withCredentials: true }, data: JSON.stringify({ gfg_id: post_id }), success:function(result) { $('.spinner-loading-overlay:eq(0)').remove(); $('.improve-modal--overlay').hide(); $('.unlocked-status--improve-modal-content').css("display","none"); $('.create-improvement-redirection-to-write').attr('href',writeUrl + 'improve-post/' + `${result.id}` + '/', '_blank'); $('.create-improvement-redirection-to-write')[0].click(); }, error:function(e) { showErrorMessage(e.responseJSON,e.status) }, }); } else { if(loginData && !loginData.isLoggedIn) { $('.improve-modal--overlay').hide(); if ($('.header-main__wrapper').find('.header-main__signup.login-modal-btn').length) { $('.header-main__wrapper').find('.header-main__signup.login-modal-btn').click(); } return; } } }); $('.left-arrow-icon_wrapper').on('click',function(){ if($('.improve-modal--suggestion').is(":visible")) $('.improve-modal--suggestion').hide(); else{ } $('.improve-modal--improvement').show(); }); const showErrorMessage = (result,statusCode) => { if(!result) return; $('.spinner-loading-overlay:eq(0)').remove(); if(statusCode == 403) { $('.improve-modal--improve-content.error-message').html(result.message); jQuery('.improve-modal--overlay').show(); jQuery('.improve-modal--improvement').show(); $('.locked-status--impove-modal').css("display","block"); $('.unlocked-status--improve-modal-content').css("display","none"); $('.improve-modal--improvement').attr("status","locked"); return; } } function suggestionCall() { var editorValue = suggestEditorInstance.getValue(); var suggest_val = $(".ContentEditable__root").find("[data-lexical-text='true']").map(function() { return $(this).text().trim(); }).get().join(' '); suggest_val = suggest_val.replace(/\s+/g, ' ').trim(); var array_String= suggest_val.split(" ") //array of words var gCaptchaToken = $("#g-recaptcha-response-suggestion-form").val(); var error_msg = false; if(suggest_val != "" && array_String.length >=4){ if(editorValue.length { jQuery('.ContentEditable__root').focus(); jQuery('#suggestion-modal-alert').hide(); }, 3000); } } document.querySelector('.suggest-bottom-btn').addEventListener('click', function(){ jQuery('body').append('
'); jQuery('.spinner-loading-overlay').show(); if(loginData && loginData.isLoggedIn) { suggestionCall(); return; } // script for grecaptcha loaded in loginmodal.html and call function to set the token setGoogleRecaptcha(); }); $('.improvement-bottom-btn.create-improvement-btn').click(function() { //create improvement button is clicked $('body').append('
'); $('.spinner-loading-overlay').show(); // send this option via create-improvement-post api jQuery.ajax({ url: writeApiUrl + 'create-improvement-post/?v=1', type: "POST", contentType: 'application/json; charset=utf-8', dataType: 'json', xhrFields: { withCredentials: true }, data: JSON.stringify({ gfg_id: post_id }), success:function(result) { $('.spinner-loading-overlay:eq(0)').remove(); $('.improve-modal--overlay').hide(); $('.create-improvement-redirection-to-write').attr('href',writeUrl + 'improve-post/' + `${result.id}` + '/', '_blank'); $('.create-improvement-redirection-to-write')[0].click(); }, error:function(e) { showErrorMessage(e.responseJSON,e.status); }, }); });
"For an ad-free experience and exclusive features, subscribe to our Premium Plan!"
Continue without supporting
`; $('body').append(adBlockerModal); $('body').addClass('body-for-ad-blocker'); const modal = document.getElementById("adBlockerModal"); modal.style.display = "block"; } function handleAdBlockerClick(type){ if(type == 'disabled'){ window.location.reload(); } else if(type == 'info'){ document.getElementById("ad-blocker-div").style.display = "none"; document.getElementById("ad-blocker-info-div").style.display = "flex"; handleAdBlockerIconClick(0); } } var lastSelected= null; //Mapping of name and video URL with the index. const adBlockerVideoMap = [ ['Ad Block Plus','https://media.geeksforgeeks.org/auth-dashboard-uploads/abp-blocker-min.mp4'], ['Ad Block','https://media.geeksforgeeks.org/auth-dashboard-uploads/Ad-block-min.mp4'], ['uBlock Origin','https://media.geeksforgeeks.org/auth-dashboard-uploads/ub-blocke-min.mp4'], ['uBlock','https://media.geeksforgeeks.org/auth-dashboard-uploads/U-blocker-min.mp4'], ] function handleAdBlockerIconClick(currSelected){ const videocontainer = document.getElementById('ad-blocker-info-div-gif'); const videosource = document.getElementById('ad-blocker-info-div-gif-src'); if(lastSelected != null){ document.getElementById("ad-blocker-info-div-icons-"+lastSelected).style.backgroundColor = "white"; document.getElementById("ad-blocker-info-div-icons-"+lastSelected).style.borderColor = "#D6D6D6"; } document.getElementById("ad-blocker-info-div-icons-"+currSelected).style.backgroundColor = "#D9D9D9"; document.getElementById("ad-blocker-info-div-icons-"+currSelected).style.borderColor = "#848484"; document.getElementById('ad-blocker-info-div-name-span').innerHTML = adBlockerVideoMap[currSelected][0] videocontainer.pause(); videosource.setAttribute('src', adBlockerVideoMap[currSelected][1]); videocontainer.load(); videocontainer.play(); lastSelected = currSelected; }

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences