JavaScript: Download Object Data

(Last Updated On: )

Sometimes you just want to send an object to be downloaded in which you don’t have any special requirements just download the data. To do so is really straight forward. Create the blob with the type then create the blobs object url.

var blob = new Blob([JSON.stringify(myDataObject)], {type: "application/force-download"});
url  = URL.createObjectURL(blob);

<a target="_blank" href={url} download="file.extension" />