# Examples

The [Data Schema](/documentation-and-resources/components-and-data/object-types/object-type-details/data-schema.md) is the essence of your [Object Type](/documentation-and-resources/components-and-data/object-types.md). Created using JSON, Data Schemas can be as simple or complex as your needs demand. Several examples of this powerful Contextual capability are provided.

{% tabs %}
{% tab title="Customer" %}
An example of a Customer Object Type typical to a simple business or CRM system.

| Object Type Definition | Value                    |
| ---------------------- | ------------------------ |
| ID                     | customer                 |
| Display Name           | Customer                 |
| Display Name (Plural)  | Customers                |
| Description            | Customers of my company. |
| Category               | Data                     |

{% hint style="info" %}
[AI Assistant](/documentation-and-resources/components-and-data/object-types/object-type-details/data-schema/ai-assistant.md) prompts you might consider to modify this schema:

* "Add validation to the zip property"
* "Instead of separate name fields, combine into a single fullName field"
* "Add validation to the phone property so it meets US standard"
* "Add a description to each property"
  {% endhint %}

{% code title="Example Data Schema" lineNumbers="true" %}

```json
{
  "primaryKey": "customerId",
  "type": "object",
  "properties": {
    "customerId": {
      "type": "string",
      "generate": {
        "type": "uuid",
        "format": "v4"
      }
    },
    "firstName": {
      "type": "string",
      "minLength": 1
    },
    "lastName": {
      "type": "string",
      "minLength": 1
    },
    "email": {
      "type": "string",
      "format": "email",
      "minLength": 1
    },
    "phone": {
      "type": "string",
      "minLength": 1
    },
    "address": {
      "type": "object",
      "properties": {
        "street": {
          "type": "string",
          "minLength": 1
        },
        "city": {
          "type": "string",
          "minLength": 1
        },
        "state": {
          "type": "string",
          "minLength": 1
        },
        "zip": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "street",
        "city",
        "state",
        "zip"
      ]
    }
  },
  "required": [
    "firstName",
    "lastName",
    "email",
    "phone",
    "address"
  ],
  "additionalProperties": false
}
```

{% endcode %}

This schema defines an object for storing customer data, using `customerId` as the primary key, which is generated as a UUID version 4 string. The schema includes properties such as `firstName`, `lastName`, `email` (which must be a valid email format), and `phone`, each requiring a minimum length of one character. It also details an `address` object with mandatory properties like `street`, `city`, `state`, and `zip`, each also requiring a minimum length of one. All these properties are required for the object to be valid. Additionally, the schema disallows any properties not explicitly defined (`additionalProperties` is set to false).
{% endtab %}

{% tab title="Invoice" %}
An example of an Invoice Object Type, typical to a simple business or CRM system.

| Object Type Definition | Value                     |
| ---------------------- | ------------------------- |
| ID                     | invoice                   |
| Display Name           | Invoice                   |
| Display Name (Plural)  | Invoices                  |
| Description            | Invoices for my services. |
| Category               | Data                      |

{% hint style="info" %}
[AI Assistant](/documentation-and-resources/components-and-data/object-types/object-type-details/data-schema/ai-assistant.md) prompts you might consider to modify this schema:

* "Add validation to the zip property"
* "Add state names and 2-letter abbreviations to the state property"
* "Add validation to the phone property so it meets US standard"
* "Add a description to each property"
  {% endhint %}

{% code title="Example Data Schema" lineNumbers="true" %}

```json
{
  "primaryKey": "invoiceId",
  "type": "object",
  "properties": {
    "invoiceId": {
      "type": "string",
      "generate": {
        "type": "uuid",
        "format": "v4"
      }
    },
    "clientName": {
      "type": "string",
      "minLength": 1
    },
    "clientAddress": {
      "type": "object",
      "properties": {
        "street": {
          "type": "string",
          "minLength": 1
        },
        "city": {
          "type": "string",
          "minLength": 1
        },
        "state": {
          "type": "string",
          "minLength": 1
        },
        "zip": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "street",
        "city",
        "state",
        "zip"
      ]
    },
    "consultantName": {
      "type": "string",
      "minLength": 1
    },
    "date": {
      "type": "string",
      "format": "date"
    },
    "hours": {
      "type": "number",
      "minimum": 1
    },
    "hourlyRate": {
      "type": "number",
      "minimum": 1
    },
    "totalAmount": {
      "type": "number",
      "minimum": 1
    },
    "status": {
      "type": "string",
      "enum": [
        "draft",
        "sent",
        "paid",
        "overdue"
      ]
    }
  },
  "required": [
    "clientName",
    "clientAddress",
    "consultantName",
    "date",
    "hours",
    "hourlyRate",
    "totalAmount",
    "status"
  ],
  "additionalProperties": false
}
```

{% endcode %}

This schema defines an object for an invoice, using `invoiceId` as the primary key, which is generated as a UUID version 4 string. It includes properties such as `clientName`, `clientAddress` (an embedded object with required properties like `street`, `city`, `state`, and `zip`), `consultantName`, `date` (in date format), `hours` (a number with a minimum of 1), `hourlyRate` (also a number with a minimum of 1), `totalAmount` (a number with a minimum of 1), and `status` (restricted to "draft", "sent", "paid", or "overdue"). All properties listed are required, and no additional properties are allowed outside those defined.
{% endtab %}

{% tab title="ZIP Code" %}
An example of a ZIP Code Object Type which could be used to store a record of every ZIP Code in the United States, and associated geo-location information.

| Object Type Definition | Value                                   |
| ---------------------- | --------------------------------------- |
| ID                     | zipcode                                 |
| Display Name           | ZIP Code                                |
| Display Name (Plural)  | ZIP Codes                               |
| Description            | ZIP Codes throughout the United States. |
| Category               | Setting                                 |

{% hint style="info" %}
[AI Assistant](/documentation-and-resources/components-and-data/object-types/object-type-details/data-schema/ai-assistant.md) prompts you might consider to modify this schema:

* "Add arrays for the cities, states, and counties associated with each ZIP code"
* "Add a description to each property"
  {% endhint %}

{% code title="Example Data Schema" lineNumbers="true" %}

```json
{
  "primaryKey": "zipCode",
  "type": "object",
      "properties": {
        "zipCode": {
          "description": "Postal code",
          "type": "string",
          "pattern": "^\\d{5}(?:[-\\s]\\d{4})?$"
      }
  },
  "required": [
    "zipCode"
  ],
  "additionalProperties": false
}
```

{% endcode %}

This schema defines an object that primarily uses `zipCode` as its unique identifier. The `zipCode` is a required property, characterized by the type "string" and must follow a specific pattern. The acceptable format for the `zipCode` is either a five-digit number or a five-digit number followed by a dash or space and then four additional digits (e.g., 12345 or 12345-6789). The schema restricts any properties other than those explicitly defined (`additionalProperties` is set to false), emphasizing that the only data this schema will accept pertains to the `zipCode`.
{% endtab %}

{% tab title="Freeform" %}
An example of a Freeform Object Type which simply creates a unique ID and records any valid JSON properties and values that are provided.

| Object Type Definition | Value                                                 |
| ---------------------- | ----------------------------------------------------- |
| ID                     | freeform                                              |
| Display Name           | Freeform                                              |
| Display Name (Plural)  | Freeform                                              |
| Description            | Uniquely identified records of various schema shapes. |
| Category               | Data                                                  |

{% code title="Example Data Schema" lineNumbers="true" %}

```json
{
  "primaryKey": "id",
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "generate": {
        "type": "uuid",
        "format": "v4"
      }
    }
  }
}
```

{% endcode %}

This schema defines a simple object where the primary key is `id`. The `id` is a string that is automatically generated as a UUID version 4. The schema specifies only this one property, focusing solely on the identifier for the object. Notably, the schema does not restrict additional properties, meaning it will allow any data posted to be processed alongside the `id`.
{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.contextual.io/documentation-and-resources/components-and-data/object-types/examples.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
