I'm append JSON into a file.I'm using appendFile for append into the file. I'm using a specific JSON structure
And my problem is: how can I change the character '][' by ','
I think I need to use readFile and the function replace ?
Need help, thanks in advance
var table = []
table.push({"executionDate":date,
"issueID":key,
"priority":{
"jira": priority,
"computed":score1
},
"expectedValue":{
"jira": expected,
"computed":score2
}
})
var json = JSON.stringify(table);
fs.appendFile('myjsonfile.json', json, 'utf8', function (err) {
if (err) console.error(err)
});
Actual result:
[{
"executionDate": 25 / 03 / 2019,
"issueID": 1,
"priority": {
"jira": important,
"computed": 10
},
"expectedValue": {
"jira": expected,
"computed": 20
}
}
]
[{
"executionDate": 26 / 03 / 2019,
"issueID": 2,
"priority": {
"jira": important,
"computed": 20
},
"expectedValue": {
"jira": expected,
"computed": 30
}
}]
Expected result:
[{
"executionDate": 25 / 03 / 2019,
"issueID": 1,
"priority": {
"jira": important,
"computed": 10
},
"expectedValue": {
"jira": expected,
"computed": 20
}
}
,
{
"executionDate": 26 / 03 / 2019,
"issueID": 2,
"priority": {
"jira": important,
"computed": 20
},
"expectedValue": {
"jira": expected,
"computed": 30
}
}]