-
-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make json.tool soak up input before opening output for writing #89807
Comments
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. |
This is arguably a bugfix since truncating the |
Thanks, Chris! ✨ 🍰 ✨ |
The proposed path does not work for |
I left the current behaviour for --json-lines untouched, on purpose. Simplest fix for the case in this current code would be: iff infile equals outfile (minding their types), call list(objs) on the generator[1] to materialise it in one go. The only case where that would break would be when infile == outfile and is a named pipe, but I can't imagine why I would want to both read and write to the same FIFO, other than comedic effect. [1] Line 65 in 122ca4d
|
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: