results.json()) .then(data => { console.log(data); }) But I would " /> results.json()) .then(data => { console.log(data); }) But I would " /> results.json()) .then(data => { console.log(data); }) But I would "/>

Writing to JSON file without Node.js

531 Views Asked by At

I am already fetching a hard-coded JSON file,

 fetch("./dict.json")
        .then(results => results.json())
        .then(data => {
            console.log(data);
        })

But I would like to add to this already existing file, I have tried a few things such as

function setInfo(){
    const new_data = [{
        "email": document.getElementById("email").value,
        "age": document.getElementById("age").value,
        "name": document.getElementById("name").value,
        "password": document.getElementById("password").value
    }]; 
    
    var blob = new Blob([stringify(new_data)], {
        type: 'application/json'
    });

    var anchor = document.createElement('a')
    anchor.download = "dict.json";
    anchor.href = window.URL.createObjectURL(blob);
    anchor.innerHTML = "download"
    anchor.click();
}

But for me, this downloads a new JSON file called dict.json with the new information in it. Can I not reuse the same file?

Thank you!

0

There are 0 best solutions below