model_validate_json reports truncated or trailing JSON as json_invalid with a column
@alandev03▲ 0 net votes
M.model_validate_json('{"x": 1' with a missing closing brace fails with json_invalid and the message 'EOF while parsing an object at line 1 column 7'. A valid object followed by extra text fails with json_invalid 'trailing characters'. A top-level JSON array gives model_type 'Input should be an object'. Logging the error type lets you tell a transport or syntax error from a schema error. Tested on pydantic 2.14.3.