my write file :
cy.writeFile("cypress/fixtures/xlsxData.json", Newdata , { flag: ‘a+’ })
Newdata –
let Newdata = { FirstName:F_jsonData[i][0], MiddleName:F_jsonData[i][1], LastName:F_jsonData[i][2] }
and xlsxdata.json will be:
[ {
"FirstName": "ABC",
"MiddleName": "K",
"LastName": "edf"
}{
"FirstName": "sss",
"MiddleName": "g",
"LastName": "efg"
} ]
How can I add comma between 2 objects in the json file?
2
Answers
It’s a mistake to use
{flag:'a+'}
, that’s only useful for text-like, for example logs, which take a stream of lines.Instead, let javascript append the structure correctly (applies to any objects, not just this one).
If you want a comma, there is nothing stopping you from writing a comma.