Ok so I'm trying to make a dictionary rename function but I keep getting the error Object of type '_NestedList' is not JSON serializable
no matter what I do, I've tried a few things which when I try them on repl they work no issues... except when I try them on my end.
The json for it looks like custom["commands"]["command"]["beep"]
so what I'm trying to do is change it to custom["commands"]["command"]["boom"]
{
"command": {},
"commands": {
"command": {
"beep": {
"created": "2018-11-04 16:32:50.013260",
"created2": 1541349170.0132835,
"createdby": "me",
"disablefor": [],
"enabledfor": [],
"message": "asd",
"public": "self",
"type": "text",
"unsendtimer": 0,
"unsendtrigger": false
},
"bep": {
"created": "2018-11-04 16:34:38.723840",
"created2": 1541349278.7238638,
"createdby": "me",
"disablefor": [],
"enabledfor": [],
"message": "asd",
"public": "self",
"type": "text",
"unsendtimer": 0,
"unsendtrigger": false
},
"boop": {
"STKID": "423",
"STKPKGID": "1",
"STKVER": "100",
"created": "2018-10-27 00:53:38.067740",
"created2": 1540601618.0677645,
"createdby": "me",
"disablefor": [
"u69a0086845f2d38c5ecfd91a7601f3c1",
"ua2ed27b7932f647b492daa68ef33c0cc"
],
"enabledfor": [],
"message": "8775249726676",
"public": "on",
"type": "sticker",
"unsendtimer": 0,
"unsendtrigger": true
}
},
"commandgrab": false,
"commandgroup": ""
}
}
that's what the json file looks like, Anyone has any suggestions I'd love them thanks
You are using the livejson package, rather than python's built-in json package.
livejson json structures are a tree of livejson objects; evidently livejson does not directly support moving these objects between keys:
>>> import livejson
>>> test['foo'] = {'bar': {'baz': [1, 2, 3]}
>>> test
{'foo': {'bar': {'baz': [1, 2, 3]}}}
>>> type(test['foo']['bar']['baz'])
<class 'livejson._NestedList'>
>>> test['foo']['bar']['quux'] = test['foo']['bar']['baz']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
...
TypeError: Object of type _NestedList is not JSON serializable
livejson objects have a data
property that returns the standard python lists and dicts that livejson is wrapping, so you need to use this property to reassign the key's value:
>>> test['foo']['bar']['quux'] = test['foo']['bar']['baz'].data
# Now remove the old value
>>> del test['foo']['bar']['baz']
>>> test
{'foo': {'bar': {'quux': [1, 2, 3]}}}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.