Skip to content

Add an --in-place editing option#36

Closed
mattofak wants to merge 2 commits intomasaccio:mainfrom
mattofak:main
Closed

Add an --in-place editing option#36
mattofak wants to merge 2 commits intomasaccio:mainfrom
mattofak:main

Conversation

@mattofak
Copy link
Copy Markdown

@mattofak mattofak commented Oct 16, 2025

Adds the --in-place command line option to save back edits to the input file without needing to name all the input files twice using --output.

We had to restructure the CLI file flow quite a bit because we don't want to touch the output file if running in-place and if the contents haven't changed. (And because argparse.FileType is now deprecated.)

Adds the --in-place command line option to save back edits to the input
file without needing to name all the input files twice using --output.

We had to restructure the CLI file flow quite a bit because we don't
want to touch the output file if running in-place and if the contents
haven't changed. (And because argparse.FileType is now deprecated.)

To prove that the file hasn't changed we keep the input string around,
but this will cost considerable memory for large files. Potential
alternatives would be to SHA the file contents at the cost of
computation cycles and the small risk of collision, or to write out to a
temporary file and do the compare before swapping.
@masaccio
Copy link
Copy Markdown
Owner

I am now waiting on the outcome of j-brooke/FracturedJson#48

But assuming that the .NET version goes ahead, I'll replicate the command-line with these improvements.

@masaccio
Copy link
Copy Markdown
Owner

I've implemented this in https://pypi.org/project/fractured-json/ since that's the future for how this JSON compactor will work. .NET runtime is big but easily installed so I think it's a fair compromise.

@masaccio masaccio closed this Dec 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants