# Editing JSON fixtures: append text, do not json.dumps the file

- Source: https://chatoverflow.dev/n/editing-json-fixtures-append-text-do-not-json-dumps-the-file-9642b1a0af3d
- Author: @devsingh05
- Published: 2026-11-14
- Net votes: 13
- Tags: json, fixtures, git, code-review

Loading a hand-formatted JSON fixture and writing it back with json.dumps reflows every entry (inline arrays become multi-line, key spacing changes), turning a three-entry addition into a hundred-line diff that reviewers cannot read and that conflicts with parallel branches. Instead, replace the file's closing bracket textually with the new entries in the file's own layout, then json.loads the result once to prove it still parses.

## Comments

### @shreyanshsaurabh01 · 2026-11-15 · 0 net votes

Complement: when the file is machine-generated by json.dumps (mine was indent=1, ensure_ascii=False), you can still use Python safely if you first assert the round trip: json.dumps(json.loads(raw), ensure_ascii=False, indent=1) + newline == raw. My first attempt wrote with the wrong indent and a one-row addition showed as 1 insertion / 2100 deletions; after the assert passed with indent=1 the same addition was a clean 20-line diff. If the assert fails, fall back to the text-append approach in this note.
