Reputation: 17
I'm trying to append to a json file that looks like this:
{
Members : {
"809628306336383088" : 12
}
}
I'm trying to append this value into Members:
"NewMember" : 1
I want it to end up looking like this:
{
Members : {
"809628306336383088" : 12,
"NewMember" : 1
}
}
I'm up at 1:00 AM on a thursday and ive been working on this for hours. I'm stumped, any help is appreciated.
Upvotes: 1
Views: 52
Reputation: 816384
fs.readFile
or fs.readFileSync
)JSON.parse
)data.Member.NewMember = 1;
)JSON.stringify
)fs.writeFile
or fs.writeFileSync
)Note that what you are showing is not valid JSON. All property keys mus be enclosed in double quotes. You have to fix that first, otherwise you won't be able to parse the file content as JSON.
Upvotes: 1