Skip to content

Allow JSON validation of JSON data already loaded using json.load() #11154

@pallgeuer

Description

@pallgeuer

Initial Checks

  • I have searched Google & GitHub for similar requests and couldn't find anything
  • I have read and followed the docs and still think this feature is missing

Description

I searched but didn't find where/how this would be possible already, especially in a simple straightforward way.

Suppose I have a JSON string, then I can do MyModel.model_validate_json(json_str, strict=True) to validate the JSON using 'looser' JSON rules to get an instance of MyModel (as per here). How can I do exactly the same if I only have access to json.loads(json_str)?

Calling MyModel.model_validate() uses different (Python) validation rules, and MyModel.model_validate_json() only accepts the raw string. Converting the loaded JSON data back to string just to validate it again seems backwards. The feature request would be to have a simple top-level way of passing already-loaded JSON data (Python objects) through JSON-style validation rules.

Affected Components

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions