Modifying JSON attribute
For modifying the JSON attribute value, you use the standard Python list and dict API as well:
>>> Product[1].info['colors'].append('Silver')
>>> Product[1].info['colors']
['Black', 'Grey', 'Gold', 'Silver']
Now, on commit, the changes will be stored in the database. In order to track the changes made in the JSON structure, Pony uses its own dict and list implementations which inherit from the standard Python dict and list.
Below is a couple more examples of how you can modify the the JSON value.
p = Product[1]
# assigning a new value
p.info['display']['size'] = 4.7
# popping a dict value
display_size = p.info['display'].pop('size')
# removing a dict key using del
del p.info['display']
# adding a dict key
p.info['display']['resolution'] = [1440, 2560]
# removing a list item
del p.info['colors'][0]
# replacing a list item
p.info['colors'][1] = ['White']
# replacing a number of list items
p.info['colors'][1:] = ['White']
All of the actions above are regular Python operations with attributes, lists and dicts.