You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Converting all Structs (including nested ones) to dict. #594
msgspec.structs.asdict doesn't recurse into struct fields when converting structs to dicts, it only applies to the top-level struct.
To recurse through all fields, lowering complex types like structs/dataclasses/attrs/... to simpler types like int/str/dict/... you'll want to use msgspec.to_builtins. This is effectively the same as msgspec.json.decode(msgspec.json.encode(obj)), but is much more efficient.
Activity
zulqasar commentedon Nov 27, 2023
Currently I am using this fix.
jcrist commentedon Nov 28, 2023
msgspec.structs.asdictdoesn't recurse into struct fields when converting structs to dicts, it only applies to the top-level struct.To recurse through all fields, lowering complex types like structs/dataclasses/attrs/... to simpler types like
int/str/dict/... you'll want to usemsgspec.to_builtins. This is effectively the same asmsgspec.json.decode(msgspec.json.encode(obj)), but is much more efficient.See docs here and here.