I've been developing a Discord bot and I'm currently storing currency values in a json file. The functionality is working smoothly, but the issue I'm facing is that it's adding them to the json file in a single line which makes it difficult to read.
Here's the code snippet:
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 here's how the current json output 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 prefer the json format to be structured like this:
{
"Layers#0169": {
"Cash": 0,
"Bank": 0,
"Net Worth": 0
},
"Anth'auwe#0169": {
"cash": 0,
"bank": 0,
"Net Worth": 0
}
}