0

I'm using python 2.7 and I'm trying to write a file with some encoding (in my 'finalList' variable the encoding is: 0xe9)

This is how I'm trying to write my file using the 'json' and 'io' modules

import json
import io

with io.open('my.json', 'w', encoding='utf8') as outfile:
    json.dump(finalList, outfile)
NewToJS
  • 2,011
  • 4
  • 35
  • 62

1 Answers1

1

json.dump accepts an encoding arg which defaults to 'utf-8':

$ pydoc json.dump
Help on function dump in json:

json.dump = dump(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, cls=None, indent=None, separators=None, encoding='utf-8', default=None, sort_keys=False, **kw)
jcomeau_ictx
  • 37,688
  • 6
  • 92
  • 107