Items are added to the list using append() :
>>> data = {'list': [{'a':'1'}]} >>> data['list'].append({'b':'2'}) >>> data {'list': [{'a': '1'}, {'b': '2'}]}
If you want to add an element to a specific place in the list (for example, to the beginning), use insert() instead:
>>> data['list'].insert(0, {'b':'2'}) >>> data {'list': [{'b': '2'}, {'a': '1'}]}
After that, you can again compile JSON from the dictionary you changed:
>>> json.dumps(data) '{"list": [{"b": "2"}, {"a": "1"}]}'
myaut
source share