import json
    
    from pydantic import BaseModel, Field
    
    
    def pop_default(s):
        s.pop('default')
    
    
    class Model(BaseModel):
        a: int = Field(default=1, json_schema_extra=pop_default)
    
    
    print(json.dumps(Model.model_json_schema(), indent=2))
    

JSON output:

    
    
    {
      "properties": {
        "a": {
          "title": "A",
          "type": "integer"
        }
      },
      "title": "Model",
      "type": "object"
    }
    

###  ` WithJsonSchema ` annotation  ¶

API Documentation

[ ` pydantic.json_schema.WithJsonSchema `
](../../api/json_schema/#pydantic.json_schema.WithJsonSchema)  

Tip

Using [ ` WithJsonSchema `
](../../api/json_schema/#pydantic.json_schema.WithJsonSchema) ] is preferred
over  implementing ` __get_pydantic_json_schema__ ` for custom types, as it's
more simple and less error-prone.

The [ ` WithJsonSchema `
](../../api/json_schema/#pydantic.json_schema.WithJsonSchema) annotation can
be used to override the generated (base) JSON schema for a given type without
the need to implement ` __get_pydantic_core_schema__ ` or `
__get_pydantic_json_schema__ ` on the type itself.

This provides a way to set a JSON schema for types that would otherwise raise
errors when producing a JSON schema, such as ` Callable ` , or types that have
an [ ` is-instance `
](../../api/pydantic_core_schema/#pydantic_core.core_schema.is_instance_schema)
core schema.

For example, the use of a [ ` PlainValidator `
](../../api/functional_validators/#pydantic.functional_validators.PlainValidator)
in the following example would otherwise raise an error when producing a JSON
schema because the [ ` PlainValidator `
](../../api/functional_validators/#pydantic.functional_validators.PlainValidator)
is a ` Callable ` . However, by using the [ ` WithJsonSchema `
](../../api/json_schema/#pydantic.json_schema.WithJsonSchema) annotation, we
can override the generated JSON schema for the custom ` MyInt ` type:

    
    
    import json
    
    from typing_extensions import Annotated
    
    from pydantic import BaseModel, PlainValidator, WithJsonSchema
    
    MyInt = Annotated[
        int,
        PlainValidator(lambda v: int(v) + 1),
        WithJsonSchema({'type': 'integer', 'examples': [1, 0, -1]}),
    ]
    
    
    class Model(BaseModel):
        a: MyInt
    
    
    print(Model(a='1').a)
    #> 2
    
    print(json.dumps(Model.model_json_schema(), indent=2))
    

JSON output:

    
    
    {
      "properties": {
        "a": {
          "examples": [
            1,
            0,
            -1
          ],
          "title": "A",
          "type": "integer"
        }
      },
      "required": [
        "a"
      ],
      "title": "Model",
      "type": "object"
    }
    

Note

As discussed in [ this issue
](https://github.com/pydantic/pydantic/issues/8208) , in the future, it's
likely that Pydantic will add builtin support for JSON schema generation for
types like [ ` PlainValidator `
](../../api/functional_validators/#pydantic.functional_validators.PlainValidator)
, but the [ ` WithJsonSchema `
](../../api/json_schema/#pydantic.json_schema.WithJsonSchema) annotation will
still be useful for other custom types.

###  ` SkipJsonSchema ` annotation  ¶

API Documentation

[ ` pydantic.json_schema.SkipJsonSchema `
](../../api/json_schema/#pydantic.json_schema.SkipJsonSchema)  

The [ ` SkipJsonSchema `
](../../api/json_schema/#pydantic.json_schema.SkipJsonSchema) annotation can
be used to skip a including field (or part of a field's specifications) from
the generated JSON schema. See the API docs for more details.

###  Implementing ` __get_pydantic_core_schema__ ` ¶

Custom types (used as ` field_name: TheType ` or ` field_name:
Annotated[TheType, ...] ` ) as well as ` Annotated ` metadata (used as `
field_name: Annotated[int, SomeMetadata] ` ) can modify or override the
generated schema by implementing ` __get_pydantic_core_schema__ ` . This
method receives t