const data = { name: "John", age: 30 }; const fileName = "data.json"; // 1. Create a Blob of the data const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' }); // 2. Create an anchor element and trigger download const a = document.createElement("a"); a.href = URL.createObjectURL(blob); a.download = fileName; a.click(); // 3. Clean up the URL object URL.revokeObjectURL(a.href); Use code with caution.
Developers often need to trigger a JSON download directly from a web application using client-side code. Using Blobs and Object URLs download json file
Alternatively, use the tab, locate the JSON request, right-click it, and choose "Open in new tab" or "Save response" . 2. Programmatic Downloads with JavaScript const data = { name: "John", age: 30
This guide covers everything from simple browser-based downloads to automated methods using Python and JavaScript. 1. Quick Browser Methods Clean up the URL object URL
: Navigate to the JSON URL in your browser. Right-click anywhere on the page and select "Save As..." (or use Ctrl + S on Windows / Cmd + S on Mac). Ensure the file extension is set to .json . Using Developer Tools (Chrome/Edge) : Open the page containing the JSON.