Models with optional string fields were raising orjson.JSONDecodeError errors.
orjson.JSONDecodeError: unexpected character: line 1 column 1 (char 0)
Cause
The parser was attempting to parse non-JSON string like 'hi' instead of strings like '"hi"' or '{"foo": "bar"}'.
This would occur when the optional string fields actually had strings in them.
Remedy
Filter out any fields that are of type str or Optional[str] or str | None and avoid JSON-parsing their values in case their values are strings.
Thanks to @nmarusov for discovering this issue and doing the initial fixes.
Why
Models with optional string fields were raising
orjson.JSONDecodeError
errors.Cause
The parser was attempting to parse non-JSON string like 'hi' instead of strings like '"hi"' or '{"foo": "bar"}'. This would occur when the optional string fields actually had strings in them.
Remedy
Filter out any fields that are of type
str
orOptional[str]
orstr | None
and avoid JSON-parsing their values in case their values are strings.Thanks to @nmarusov for discovering this issue and doing the initial fixes.