> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dottxt.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Null

> Require a field to be present and explicitly null.

Use `"type": "null"` when a field must be present with a `null` value.

## Example

<CodeGroup>
  ```json JSON Schema theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  {
    "type": "object",
    "properties": {
      "middle_name": { "type": "null" },
      "deprecated_field": { "type": "null" }
    },
    "required": ["middle_name", "deprecated_field"],
    "additionalProperties": false
  }
  ```

  ```python Pydantic theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  from pydantic import BaseModel, ConfigDict

  class Payload(BaseModel):
      model_config = ConfigDict(extra="forbid")

      middle_name: None
      deprecated_field: None
  ```

  ```typescript Zod theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  import { z } from "zod";

  const payloadSchema = z
    .object({
      middle_name: z.null(),
      deprecated_field: z.null(),
    })
    .strict();
  ```
</CodeGroup>

## `null` vs optional fields

* `type: "null"`: field is present and value is `null`.
* Optional field: field may be absent.
* Optional field + `type: "null"`: field is either absent or present with null.

If you want a field that can be either string or null, use a union type:

<CodeGroup>
  ```json JSON Schema theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  {
    "type": "object",
    "properties": {
      "value": {
        "anyOf": [
          { "type": "string" },
          { "type": "null" }
        ]
      }
    },
    "required": ["value"],
    "additionalProperties": false
  }
  ```

  ```python Pydantic theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  from pydantic import BaseModel, ConfigDict

  class Payload(BaseModel):
      model_config = ConfigDict(extra="forbid")

      value: str | None
  ```

  ```typescript Zod theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  import { z } from "zod";

  const payloadSchema = z
    .object({
      value: z.string().nullable(),
    })
    .strict();
  ```
</CodeGroup>

## Related

* [Optional vs Null cookbook](/json-schema/optional-vs-null)
* [Object reference](/json-schema/reference/object)
