#29476·polars

Consistent JSON reading of Struct and Map

Author: dancsiCreated Sep 23, 2026Updated Sep 29, 2026
LabelsA-dtype-structA-io-json

Follow-up to Map JSON support (#29125).

The default JSON parser uses an unordered hash table if the object has more than 32 keys. This means that input field order is not preserved in this case, affecting read_json, read_ndjson/scan_ndjson (top-level columns and nested structs) and str.json_decode().

On top of that, Struct parsing with duplicate keys is inconsistent with the decisions we made for Map

  • If the Struct schema is given, we call insert_unique_unchecked, which is unspecified if there are duplicate keys
  • If the schema is inferred, duplicates raise DuplicateError.

Map reads will use first position, last value for deduplication.