Fix writing JSON on Python 2