How to Convert JSON to Blob in JavaScript ? Last Updated : 18 Apr, 2024 Comments Improve Suggest changes Like Article Like Report This article explores how to convert a JavaScript Object Notation (JSON) object into a Blob object in JavaScript. Blobs represent raw data, similar to files, and can be useful for various tasks like downloading or processing JSON data. What is JSON and Blob?JSON (JavaScript Object Notation): A lightweight format for storing and transmitting data. It uses key-value pairs to represent structured data.Blob (Binary Large Object): A Blob represents a raw data object that can hold various types of data, including text, images, or even audio.Below are the methods for converting JSON data to a Blob object: Table of Content Using JSON.stringify and Blob constructorUsing fetch API (for pre-existing JSON data)Using JSON.stringify and Blob constructorThis approach involves stringifying the JSON object into a human-readable format and then creating a Blob object from the string. Example: This example shows the use of the above-explained approach. JavaScript const {Blob} = require('buffer'); const jsonData = { name: "Example Data", value: 10 }; // Stringify the JSON object const jsonString = JSON.stringify(jsonData); // Create a Blob object with the JSON string and // set the content type as "application/json" const blob = new Blob([jsonString], { type: "application/json" }); // Blob object representing the JSON data console.log(blob); OutputBlob { size: 34, type: 'application/json' } Using fetch API (for pre-existing JSON data)If you already have the JSON data as a URL, you can use the fetch API to retrieve it and then convert it to a Blob object. Example: This example shows the use of the above-explained approach. JavaScript const jsonUrl = "https://example.com/data.json"; fetch(jsonUrl) .then(response => response.blob()) .then(blob => { console.log(blob); // Blob object containing the downloaded JSON data }) .catch(error => console.error(error)); } Choosing the Right Method: Use the first method if you have the JSON data as a JavaScript object. Use the second method if you have the JSON data stored remotely as a file accessible through a URL.Conclusion:By following these methods, you can effectively convert JSON data into Blobs for further processing or download in your JavaScript applications. Remember to specify the appropriate content type ("application/json") when creating the Blob to ensure correct data interpretation. Comment More infoAdvertise with us Next Article How to Convert JSON to Blob in JavaScript ? htomarec8c Follow Improve Article Tags : JavaScript Web Technologies JSON Similar Reads How to Convert Blob Data to JSON in JavaScript ? When dealing with Blob data in JavaScript, such as binary data or files, we may need to convert it into JSON format for doing so JavaScript provides us with various methods as listed below. Table of Content Using FileReader APIUsing TextDecoder APIUsing FileReader APIIn this approach, we first use t 2 min read How to Convert JSON to base64 in JavaScript ? Base 64 is the encoding scheme that represents binary data in a printable ASCII format, commonly used for data serialization and transmission. Table of Content Using btoa functionUsing Manual ConversionUsing btoa functionIn this approach, we're using btoa to encode a UTF-8 string representation of a 2 min read How to Convert Map to JSON in JavaScript ? In JavaScript, when working with data, you might encounter situations where you need to convert a Map object into a JSON format. This can be useful for sending data over the network, storing data in local storage, or interfacing with APIs that expect JSON data. Converting a Map to JSON means convert 3 min read How to Convert XML to JSON in JavaScript? To convert XML to JSON in JavaScript, various methods and libraries and be used. Here, we use xml-js library that provides xml2json function to convert XML to JSON data. It takes XML data as input and gives the JSON objects as output. We can also use the DOMParser from the xmldom package to convert 2 min read How to Convert CSV to JSON in JavaScript ? In this article, we will explain different ways to change Comma-Separated Values (CSV) data into JavaScript Object Notation (JSON) format, step-by-step. We'll break down each method with clear explanations and examples. There are several approaches available in JavaScript to convert CSV to JSON in J 3 min read How to Convert HTML to JSON in JavaScript ? Converting HTML to JSON is important for structured data extraction and integration with JavaScript applications. Here, we will learn different approaches to converting HTML to JSON in JavaScript. Below are the approaches to convert html to JSON in JavaScript: Table of Content Using html-to-json Lib 2 min read How to Convert Excel to JSON in JavaScript ? Converting Excel spreadsheets to JSON format is a common requirement in various applications. JavaScript code utilizes the read-excel-file library to parse the Excel data, convert it to JSON format, and display it. Additionally, it provides functionality to download the generated JSON file. Approach 3 min read How to Convert JSON to Excel in JavaScript? It is often necessary to export or download JSON data in the form of Excel spreadsheets when developing web applications, any web developer would be able to go through this article as it provides a useful function of converting JSON files to Excel format using SheetsJS through JavaScript.These are t 4 min read How to Convert Base64 to Blob in JavaScript? Working with files and data in web applications often involves dealing with binary data. One common scenario is converting a Base64 string into a Blob object, which can then be used in various ways, such as creating downloadable files or uploading images to a server. This article will guide you thro 4 min read How to Convert JSON to string in JavaScript ? In this article, we are going to learn the conversion of JSON to string in JavaScript. Converting JSON to a string in JavaScript means serializing a JavaScript object or data structure represented in JSON format into a textual JSON string for data storage or transmission.Several methods can be used 3 min read Like