I am working on a Discord bot and want to save currency values in a json file. It's working just fine so far, but it's appending them to the json file in one single line and although it is entirely functional, I would like to be able to read it.
This is the code
let json = jsonfile.readFileSync(balance, { throws: false })
let newBalance = {}
for (let i = 0; i < 3; i++) {
let val = embedJSON.fields[i].value
val = val.replace(",", "")
let valSplit = val.split(" ")[1]
newBalance[`${embedJSON.fields[i].name}`] = valSplit
}
json[`${user}`] = newBalance
jsonfile.writeFileSync(balance, json)
And this is what the json looks like
{"Anth'auwe#0169":{"Cash:":"200","Bank:":"399800","Net Worth:":"400000"},"Layers#0169":{"Cash:":"0","Bank:":"199838","Net Worth:":"199838"}}
If possible, I would like for it to look like this
{
"Layers#0169": {
"Cash": 0,
"Bank": 0,
"Net Worth": 0
},
"Anth'auwe#0169": {
"cash": 0,
"bank": 0,
"Net Worth": 0
}
}