Hello I allow you to contact you here because I have a problem with the FS module and I am currently doing a bot discord and directly that FS modifies the Json file an error occurs directly and tells me that there is a problem of argumentation in Json, I try to modify it manually but nothing makes it as if the file was corrupted. I have to delete the json and put it back so that the error disappears.
Someone has a request for this problem?
thank you in advance
Can we see your JSON code?
My JSON contains nothing at all, just the parentheses {}
I mean, the code that uses fs
to edit JSON.
Here’s a simple example of how you could use fs
to edit JSON:
const fs = require("fs")
const json = require("./your-json-file.json")
// Making the change.
json.helloWorld = true
json.myArray = [ 1, 2, 3 ]
// Saving back to the file.
// This overwrites the file at ./your-json-file.json
// with a stringified version of the `json` object.
fs.writeFileSync("./your-json-file.json", JSON.stringify(json))
1 Like