s a copy (by default, shallow copy) of the model. See [ Serialization ](../serialization/#modelcopy) . 
  * [ ` model_dump() ` ](../../api/base_model/#pydantic.BaseModel.model_dump) : returns a dictionary of the model's fields and values. See [ Serialization ](../serialization/#modeldump) . 
  * [ ` model_dump_json() ` ](../../api/base_model/#pydantic.BaseModel.model_dump_json) : returns a JSON string representation of [ ` model_dump() ` ](../../api/base_model/#pydantic.BaseModel.model_dump) . See [ Serialization ](../serialization/#modeldumpjson) . 
  * [ ` model_extra ` ](../../api/base_model/#pydantic.BaseModel.model_extra) : get extra fields set during validation. 
  * [ ` model_fields_set ` ](../../api/base_model/#pydantic.BaseModel.model_fields_set) : set of fields which were set when the model instance was initialized. 
  * [ ` model_json_schema() ` ](../../api/base_model/#pydantic.BaseModel.model_json_schema) : returns a jsonable dictionary representing the model as JSON Schema. See [ JSON Schema ](../json_schema/) . 
  * [ ` model_parametrized_name() ` ](../../api/base_model/#pydantic.BaseModel.model_parametrized_name) : compute the class name for parametrizations of generic classes. 
  * [ ` model_post_init() ` ](../../api/base_model/#pydantic.BaseModel.model_post_init) : perform additional initialization after the model is initialized. 
  * [ ` model_rebuild() ` ](../../api/base_model/#pydantic.BaseModel.model_rebuild) : rebuild the model schema, which also supports building recursive generic models. See  Rebuild model schema  . 
  * [ ` model_validate() ` ](../../api/base_model/#pydantic.BaseModel.model_validate) : a utility for loading any object into a model. See  Helper functions  . 
  * [ ` model_validate_json() ` ](../../api/base_model/#pydantic.BaseModel.model_validate_json) : a utility for validating the given JSON data against the Pydantic model. See  Helper functions  . 

Note

See [ ` BaseModel ` ](../../api/base_model/#pydantic.BaseModel) for the class
definition including a full list of methods and attributes.

Tip

See [ Changes to ` pydantic.BaseModel ` ](../../migration/#changes-to-
pydanticbasemodel) in the [ Migration Guide ](../../migration/) for details on
changes from Pydantic V1.

##  Nested models  ¶

More complex hierarchical data structures can be defined using models
themselves as types in annotations.

    
    
    from typing import List, Optional
    
    from pydantic import BaseModel
    
    
    class Foo(BaseModel):
        count: int
        size: Optional[float] = None
    
    
    class Bar(BaseModel):
        apple: str = 'x'
        banana: str = 'y'
    
    
    class Spam(BaseModel):
        foo: Foo
        bars: List[Bar]
    
    
    m = Spam(foo={'count': 4}, bars=[{'apple': 'x1'}, {'apple': 'x2'}])
    print(m)
    """
    foo=Foo(count=4, size=None) bars=[Bar(apple='x1', banana='y'), Bar(apple='x2', banana='y')]
    """
    print(m.model_dump())
    """
    {
        'foo': {'count': 4, 'size': None},
        'bars': [{'apple': 'x1', 'banana': 'y'}, {'apple': 'x2', 'banana': 'y'}],
    }
    """
    

For self-referencing models, see [ postponed annotations
](../postponed_annotations/#self-referencing-or-recursive-models) .

##  Rebuild model schema  ¶

The model schema can be rebuilt using [ ` model_rebuild() `
](../../api/base_model/#pydantic.BaseModel.model_rebuild) . This is useful for
building recursive generic models.

    
    
    from pydantic import BaseModel, PydanticUserError
    
    
    class Foo(BaseModel):
        x: 'Bar'
    
    
    try:
        Foo.model_json_schema()
    except PydanticUserError as e:
        print(e)
        """
        `Foo` is not fully defined; you should define `Bar`, then call `Foo.model_rebuild()`.
    
        For further information visit https://errors.pydantic.dev/2/u/class-not-fully-defined
        """
    
    
    class Bar(BaseModel):
        pass
    
    
    Foo.model_rebuild()
    print(Foo.model_json_schema