Bulletproof json.dump?

Adam Funk a24061 at ducksburg.com
Mon Jul 6 06:21:48 EDT 2020


Hi,

I have a program that does a lot of work with URLs and requests,
collecting data over about an hour, & then writing the collated data
to a JSON file.  The first time I ran it, the json.dump failed because
there was a bytes value instead of a str, so I had to figure out where
that was coming from before I could get any data out.  I've previously
run into the problem of collecting values in sets (for deduplication)
& forgetting to walk through the big data object changing them to
lists before serializing.

Is there a "bulletproof" version of json.dump somewhere that will
convert bytes to str, any other iterables to list, etc., so you can
just get your data into a file & keep working?

(I'm using Python 3.7.)

Thanks!

-- 
Slade was the coolest band in England. They were the kind of guys
that would push your car out of a ditch.          ---Alice Cooper


More information about the Python-list mailing list