[issue45644] Make json.tool soak up input before opening output for writing

Chris Wesseling report at bugs.python.org
Thu Oct 28 08:59:07 EDT 2021


New submission from Chris Wesseling <chris.wesseling at xs4all.nl>:

json.tool is very cute and handy for making json readable.

But rewriting a file in place requires tools like sponge (on POSIX) or a tmpfile, because 

$ python -m json.tool foo.json foo.json

results in an empty foo.json.

I propose soaking up the infile before opening the outfile for writing, to prevent that. Much like sort -o does, but without the explicit flag.
The patch I have prepared changes no behaviours, other than preventing an empty file... (still I see this as an enhancement and not a bug fix)

----------
messages: 405182
nosy: CharString
priority: normal
severity: normal
status: open
title: Make json.tool soak up input before opening output for writing
type: enhancement

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45644>
_______________________________________


More information about the Python-bugs-list mailing list