Is there a way to use `json.dump` with `gzip`?

The gzip module supports it out of the box: just declare an encoding and it will encode the unicode string to bytes before writing it to the file:

import gzip
with gzip.open(write_file, 'wt', encoding="ascii") as zipfile:
       json.dump(data, zipfile)

Make sure you specify using text mode ('wt').

As json has encoded any non ascii character, ascii encoding is enough, but you could use any other encoding compatible with ascii for the first 128 code points like Latin1, UTF-8, etc