Skip to content

Instantly share code, notes, and snippets.

@rajeshkumaravel
Last active August 27, 2025 12:47
Show Gist options
  • Select an option

  • Save rajeshkumaravel/b744923e82e3cce7828ff0ff4b7e3e73 to your computer and use it in GitHub Desktop.

Select an option

Save rajeshkumaravel/b744923e82e3cce7828ff0ff4b7e3e73 to your computer and use it in GitHub Desktop.
chrome local storage export to json

Export

  1. Open a tab and navigate to the website where you have content to export.

  2. Open devtools and switch to the console tab.

  3. Copy and paste the following snippet in the console and Chrome should ask you to save the output file

var obj = JSON.stringify(localStorage, null, 4)
var vLink = document.createElement('a')
vBlob = new Blob([obj], {type: "octet/stream"})
vUrl = window.webkitURL.createObjectURL(vBlob);
vLink.setAttribute('href', vUrl);
vLink.setAttribute('download', vUrl.split('/')[2] + '-export.json'); // give you the website name + "export.json"
vLink.click();

Import

To restore the data to localStorage

function loadLocalStorageFromFile() {
    var fileInput = document.createElement('input');
    fileInput.type = 'file';
    fileInput.accept = '.json';  // only JSON files

    fileInput.click();

    fileInput.addEventListener('change', function(event) {
        var file = event.target.files[0];

        if (file) {
            var reader = new FileReader();
            reader.readAsText(file);
            reader.onload = function(e) {
                try {
                    var jsonData = JSON.parse(e.target.result);  // Parse the file content

                    // Iterate over all keys in the parsed JSON and set them in localStorage
                    for (var key in jsonData) {
                        if (jsonData.hasOwnProperty(key)) {
                            localStorage.setItem(key, jsonData[key]);
                        }
                    }
                    alert("LocalStorage has been updated from the JSON file.");
                } catch (err) {
                    alert("Error parsing JSON: " + err);
                }
            };

            // Handle any errors that occur during file reading
            reader.onerror = function() {
                alert("Error reading file.");
            };
        } else {
            alert("No file selected.");
        }
    });
}

loadLocalStorageFromFile(); 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment