I have a JSON file called database.json. I manage to update, add and manipulate it but couldn't manage to delete from it in a safe way. Here is the summary of my problem in code;
database.json;
{
"faqs": {
"questions": {
"1": "Question is deleted",
"2": "b",
"3": "c"
},
"answers": {
"1": "aa",
"2": "bb",
"3": "cc"
}
}
...
}
const fs = require('fs');
const ReadDatabase = fs.readFileSync('database.json');
const ReadData = JSON.parse(ReadDatabase);
let questionsObjects = ReadData.faqs.questions;
let questionObjectKeys = Object.keys(ReadData.faqs.questions)
let removed = questionObjectKeys.splice(0,1); //This
let editedDataBase = JSON.stringify(ReadData, null, 2);
fs.writeFileSync('database.json', editedDataBase);
Where I commented This, removes is and stores as removed, I can't figure out, how am I gonna update it that onto the file and just delete the key-value pair and rest will be there.