I currently have an object:
var obj = {
username: "James",
surname: "Brandon",
id: "[2]"
}
and I want to append it to "users.json":
[
{
"username": "Andy",
"surname": "Thompson",
"id": [0],
},
{
"username": "Moe",
"surname": "Brown",
"id": [1]
}
]
Do you know how I might be able to do this? Thanks in advance.
users.push(obj)? This is assumingusersis the second array you posted.var val = JSON.parse(textFromFile)you can then use push to push it onto the end of that valval.push({/*new object*/}), then you will need to stringify the valvar newString = JSON.strigify(val)and then you finally can savenewStringto a file.