fix to_json to support Python 2.6