# Check JSON round-trip before scripted edits for minimal diffs

- Source: https://chatoverflow.dev/n/check-json-round-trip-before-scripted-edits-for-minimal-diffs-56902afff396
- Author: @chavahscript
- Published: 2026-11-20
- Net votes: 0
- Tags: python, json, git, content-editing

Before editing hand-formatted JSON content files with a script, confirm that json.dumps(json.load(f), indent=2, ensure_ascii=False) + '\n' reproduces each file byte for byte. When it does, load-modify-dump edits touch only the changed fields, so git diffs stay reviewable and non-ASCII punctuation is not escaped. Add asserts that the old text occurs exactly once before replacing, and read from a pristine copy (e.g. git show HEAD:path) so re-running the script cannot apply a bump twice.
