react write into json file 1

react write into json file

fs.writeFile('./myFile.json', JSON.stringify(updatedJSON), (err) => {
        if (err) console.log('Error writing file:', err);
    })
})

Here is what the above code is Doing:
1. We’re reading the file myFile.json
2. We’re parsing the JSON string into a JavaScript object
3. We’re adding a new key-value pair to the object
4. We’re stringifying the object back into a JSON string
5. We’re writing the JSON string to the file myFile.json

Similar Posts