I recently wrote a script that I wanted to save the data on exit, and then read it in again. This is pretty trivial to do - use pickle everyone said. And I did.
But then I realised that I might want to quickly edit this data and restart the script. Using pickle makes this a bit more difficult - I would have to import the pickle file into a python shell, make the edit and save it again. What I really want to be able to do is edit the file directly... enter JSON.
So JSON needs no introduction, but that is a little frustrating about it is that there is no timestamp support. I found this out pretty quickly by running a simple json.dumps(my_dict) on my data and getting the following error:
TypeError: datetime is not JSON serializable
So after a quick Google search it turns out the standard JSON library in Python supports custom encoding and decoding. Simple I thought... but then I spent the next hour trawling through different implementation of what I wanted and no advise on what was best.
So I did what any good Python programmer would do - get all the possible solutions from the net, pretty them up and run them through timeit.
If you are interested you can download this from my Github account and select which method is best for you.