when I remove an object from an array in json with python, it ruins my json file. For example here is my python:
srs = server["purchaseableRoles"]
if srs == []:
await ctx.send("Your server has no purchaseable roles at the moment, you cant remove one.")
else:
for i in srs:
splitsrs = i.split("|")
if int(splitsrs[0]) == role.id:
print(str(i))
srs.remove(str(i))
print(srs)
f.seek(0)
json.dump(serversjson,f,sort_keys=True,indent=4)
await ctx.send("removed the role from the role shop!")
(please ignore the discord.py stuff, its in a discord bot. Also ignore the weird indents I don't know why it pasted in like that) That code is pretty much removing an object from an array in a json file, and updating it. Except for when I do that, here is my json:
{
"servers": [
{
"id": 1234,
"purchaseableRoles": [
"1234|5678"
]
},
{
"id": 813070255127396352,
"purchaseableRoles": []
}
]
}071595911774238|5"
]
}
]
}
it just gets all messed up. Here was my json before the mess-up:
{
"servers": [
{
"id": 1234,
"purchaseableRoles": [
"1234|5678"
]
},
{
"id": 813070255127396352,
"purchaseableRoles": [
"813071595911774238|5"
]
}
]
}
is there a way to prevent this? Thanks in advance if you help.