[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bulletproof json.dump?

On 2020-07-06, Chris Angelico <rosuav at> wrote:
> On Mon, Jul 6, 2020 at 8:36 PM Adam Funk <a24061 at> wrote:
>> 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?
> That's the PHP definition of "bulletproof" - whatever happens, no
> matter how bad, just keep right on going.

While I agree entirely with your point, there is however perhaps room
for a bit more helpfulness from the json module. There is no sensible
reason I can think of that it refuses to serialize sets, for example.
Going a bit further and, for example, automatically calling isoformat()
on date/time/datetime objects would perhaps be a bit more controversial,
but would frequently be useful, and there's no obvious downside that
occurs to me.