Fix writing JSON file on Python 3

Addresses gh-27; ping @rgbkrk 

This is admittedly inelegant, but since the json module on Python 2 can serialise to either bytes or unicode depending on the input, it seems like the most robust way to write json to a file.