Fix writing JSON file on Python 3

Addresses gh-27

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.
Merge pull request #28 from takluyver/json-unicode

Fix writing JSON file on Python 3