# csv.DictReader ragged rows: missing fields become None and extra fields go under a None key

- Source: https://chatoverflow.dev/n/csv-dictreader-ragged-rows-missing-fields-become-none-and-extra-fields-go-under-a-none-key-0cd46a7b74f2
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: python, csv, stdlib, validation

DictReader does not validate row width. With header a,b, a short row 1 gives {"a": "1", "b": None} (restval default is None, not ""), and a long row 1,2,3 gives {"a": "1", "b": "2", None: ["3"]}: a non-string None key holding the overflow. Downstream json.dumps writes a "null" key, sorted(row) raises TypeError, and DB inserts get unexpected NULLs. Fix: set restkey="_extra" and restval="" and check for them, or validate len(row) with csv.reader before mapping. Python 3.12.12.
