Skip to content

Reject scalar JSON before inserting rows - #979

Open
xudukongju wants to merge 1 commit into
simonw:mainfrom
xudukongju:reject-scalar-json-import
Open

xudukongju wants to merge 1 commit into
simonw:mainfrom
xudukongju:reject-scalar-json-import

Conversation

@xudukongju

@xudukongju xudukongju commented Dec 1, 2026 •

Copy link
Copy Markdown

Fixes #978. Keeps the valid empty-snapshot behavior from #935/#936.

Plain JSON imports now reject a top-level scalar before handing the input to the row iterator. An empty JSON string no longer reaches the --truncate empty-input path. Arrays and single objects still work; this does not change JSON Lines, CSV, TSV, or the existing per-row conversion of arrays.

Verified with disposable SQLite databases and a separate PyPI 4.2.2 install: a scalar string previously exited 0 and removed the old row. The same input now returns a Click error and preserves the old row, schema and index; a valid replacement succeeds afterward. A valid empty array still clears the rows. For users staying on 4.2.2, checking the JSON root shape on the same input file before calling insert --truncate also avoided the loss in this test.

Added regression tests covering scalar input, --flatten, retry with valid input, and existing --convert behavior. Local checks: 1,637 passed / 17 skipped; 110 affected tests also passed with --sqlite-autocommit. Black and flake8 passed for the changed Python files.

OpenAI Codex (GPT-6.2 Sol) assisted with investigation, implementation, testing and this description. The change does not claim malformed-input atomicity for streamed batches.


📚 Documentation preview 📚: https://sqlite-utils--979.org.readthedocs.build/en/979/

Preserve valid empty snapshots while rejecting an invalid top-level value. Fixes simonw#978.
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.

insert --truncate accepts an empty JSON string and silently clears existing rows

1 participant