# Field types

Every field type in Mojimoto - what it is for, its config options, the value the write API accepts and the value the read API returns.

A field is one named value on a content type. Its definition has a `type`, which decides what the field holds, and a `config`, which holds its label, validation rules and options.

```json
{ "type": "symbol", "config": { "label": "Title", "required": true, "max": 80 } }
```

There are fourteen types. This page gives the exact value to write for each and the exact value that comes back.

## All field types

"Write" is the value you put in `data` on the write API. "Read" is what the read API returns in `data`.

| Type | Name in the app | Write | Read |
| --- | --- | --- | --- |
| `symbol` | Short text | String | String |
| `text` | Long text | String | String |
| `rich_text` | Rich text | Array of text nodes, or an HTML string | Array of text nodes, or `null` |
| `number` | Number | Number | Number |
| `boolean` | Boolean | `true` or `false` | Boolean |
| `date` | Date & time | ISO 8601 string | The same string |
| `select` | Select | String, one of the field's `options` | String |
| `slug` | Slug | String | String |
| `media` | Media | `{ "asset_id": 7, "fit": "cover" }` | The file as an object, or `null` |
| `reference` | Reference | An entry id, `42` | The linked entry, a link stub, or `null` |
| `references` | References (many) | Array of entry ids, `[11, 12]` | Array of linked entries |
| `location` | Location | `{ "lat": 51.5, "lon": -0.12 }` | The same object |
| `json` | JSON object | Any JSON object | The same object |
| `blocks` | Blocks | Array of `{ "type", "data" }` | Array of `{ "id", "type", "data" }` |

The write API tidies three types as it stores them: rich text, media and blocks. It stores every other value as you send it and does not check its JSON type, so send a number for a number field and a boolean for a boolean field. The rules in `config` are checked when an entry is published, not when a draft is saved. See [Entries and publishing](/docs/concepts/entries-and-publishing).

## Config options

Every key is optional except where the table says otherwise.

| Key | Field types | Meaning |
| --- | --- | --- |
| `label` | All | The field's name in the app and in error messages. Without one the field id is made readable, so `link_url` becomes "Link url". |
| `required` | All | The field must have a value before the entry can be published. |
| `description` | All | Help text. The app shows it under short text, long text, number, date and select fields. |
| `placeholder` | `symbol`, `text` | Placeholder text in the app's input. |
| `min`, `max` | `symbol`, `text` | Shortest and longest length, in characters. |
| `min`, `max` | `number` | Lowest and highest value. |
| `min`, `max` | `blocks` | Fewest and most blocks. |
| `pattern` | `symbol`, `text` | A regular expression the value must match. |
| `options` | `select` | The choices, as an array of strings. |
| `content_types` | `reference`, `references` | Required. The API ids of the content types the field may link to. |
| `blocks` | `blocks` | Required. The block types, keyed by API id. |

`pattern` is a PCRE regular expression written without delimiters, for example `^[A-Z]{2}[0-9]{4}$`. It matches anywhere in the value unless you anchor it with `^` and `$`. A pattern that is not valid fails every value.

`min`, `max` and `pattern` are also enforced on `slug` and `select` fields when you set them through the API. The app's model editor manages these rules for short and long text only, and removes them from a slug or select field that is edited there.

You can send a setting next to `type` instead of inside `config`, as in `{ "type": "text", "label": "Summary" }`. It is moved into `config` when the field is saved.

## Short text and long text

`symbol` is for a single line: a title, a name, a URL. `text` is for longer plain text with line breaks. Both are strings in and out. The only difference is the input the app shows.

## Rich text

A `rich_text` value is an ordered array of nodes, one for each paragraph, heading, list item, image or table. A text node has a `type`, its plain `text` and a list of `spans` that mark formatting.

```json
[
  { "type": "heading2", "text": "Why sourdough", "spans": [] },
  {
    "type": "paragraph",
    "text": "It keeps for days. Read the guide.",
    "spans": [
      { "start": 3, "end": 8, "type": "strong" },
      {
        "start": 19,
        "end": 33,
        "type": "hyperlink",
        "data": { "link_type": "Web", "url": "https://example.com/guide" }
      }
    ]
  }
]
```

| Node `type` | Shape |
| --- | --- |
| `paragraph`, `heading1` to `heading6`, `preformatted` | `{ "type", "text", "spans" }` |
| `list-item`, `o-list-item` | `{ "type", "text", "spans" }`. Items that follow each other make one bulleted or numbered list. |
| `image` | `{ "type": "image", "url", "alt" }` |
| `table` | `{ "type": "table", "rows": [{ "cells": [{ "text", "spans", "header" }] }] }`. `header` is `true` on a heading cell. |

A span is `{ "start", "end", "type" }`, where `type` is `strong`, `em` or `hyperlink`. A hyperlink also carries `"data": { "link_type": "Web", "url": "..." }`. `start` and `end` are offsets into `text` counted in UTF-16 code units, the same way JavaScript indexes a string, and `end` is not included.

You can also write an HTML string. It is sanitised and converted to nodes before it is stored, so the read API always returns an array, never a string. An empty value is stored as `null`.

A link or image URL must start with `http`, `https` or `mailto`, or be relative. A hyperlink with any other scheme loses its link and an image with one is dropped.

Arrays are otherwise stored as sent. Nodes and spans of other types, such as an `embed` node carried over from another CMS, are kept and returned. The app's editor cannot show them, and they are lost the next time the entry is saved there.

[Rich text](/docs/frameworks/rich-text) shows how to render the array.

## Number and boolean

A `number` is a JSON number, whole or decimal. `min` and `max` bound its value. A `boolean` is `true` or `false`. A required boolean accepts `false`: only a missing value fails.

## Date and time

A `date` is a string. Write ISO 8601 with a time zone, for example `"2026-01-15T09:00:00Z"`. The value is not parsed or converted, and it comes back exactly as stored.

Filters and sorting compare dates as text, so write every date in one format. The app's date picker saves a local date and time without a zone, such as `2026-01-15T09:00`.

## Select

A `select` holds one string from the field's `options`. The app offers only those options. The write API does not check the value against them, so check it yourself before you write.

```json
{ "type": "select", "config": { "label": "Category", "options": ["news", "events", "recipes"] } }
```

## Slug

A `slug` holds the URL slug as a string. A content type can have one slug field at most.

On a collection, the slug field drives the entry's `uid`. Saving a draft or publishing with a value in the field changes the `uid` to match. A slug another entry of the same type already uses is refused with a `422`. An empty slug leaves the `uid` alone.

The field is not filled in from the `uid` you create an entry with, so send both: `"uid": "hello-world"` and `"slug": "hello-world"` in `data`.

On a single or a component there is no `uid`, and the field is an ordinary string.

## Media

A `media` field links to one file in the project's media library. Upload the file first, then write its id.

```json write
{ "cover": { "asset_id": 7, "fit": "cover" } }
```

```json read
{
  "cover": {
    "id": 7,
    "url": "https://.../cover.jpg",
    "alt": "A loaf of bread",
    "width": 2400,
    "height": 1200,
    "content_type": "image/jpeg",
    "fit": "cover"
  }
}
```

`fit` is `cover` or `contain`. It is a hint from the editor to your front end about whether the image should fill its frame or sit inside it. It does not change the file or its URL. Leave it out and it is `cover`.

`alt`, `width` and `height` belong to the file, so they are the same wherever it is used. `width` and `height` are `null` when the file has no readable dimensions, as with a PDF. An empty field is `null`, and so is a field whose file has since been deleted.

Two more shapes behave differently:

- An object describing an image with no `asset_id`, such as `{ "url": "...", "alt": "..." }`, is refused with a `422` on any save.
- A bare URL string, or `{ "url": "...", "fit": "cover" }`, is accepted for older content. It comes back with the `url` and `fit` and with `id`, `alt`, `width`, `height` and `content_type` all `null`.

Publishing checks that the file exists in the same project. [Media](/docs/concepts/media) covers uploading.

## Reference and references

A `reference` links to one entry and a `references` field links to an ordered list of them. Both need `content_types` in their config, with at least one content type that exists in the project.

```json
{ "type": "references", "config": { "label": "Related posts", "content_types": ["post"] } }
```

You write ids. You read the linked entries themselves, in the order you wrote them.

```json write
{ "author": 3, "related": [11, 12] }
```

Publishing checks that every id is an entry in the same project. [Links between entries](/docs/concepts/links) explains how they come back and how `depth` follows them.

## Location

A `location` is an object with a latitude and a longitude, `{ "lat": 51.5, "lon": -0.12 }`. The API stores and returns it as written and does not check the numbers.

> **Warning:** The app's entry editor shows a location as one line of text and saves what is typed as a string. A location object written over the API appears empty there, and is replaced by an empty value the next time the entry is saved in the app.

## JSON

A `json` field holds any JSON object and returns it unchanged. Use it for data with no fixed shape, such as settings passed straight to a chart library. The app edits it as text and refuses to save text that is not valid JSON.

Do not put page structure in a JSON field. It gets no validation and no media handling, and its contents cannot be filtered. Use a blocks field for that.

## Blocks

A `blocks` field holds an ordered list of typed sections inside the entry. Its config defines the block types and each block type has its own fields.

```json write
{ "sections": [{ "type": "hero", "data": { "heading": "Welcome" } }] }
```

```json read
{ "sections": [{ "id": "9f2c41d07a", "type": "hero", "data": { "heading": "Welcome" } }] }
```

A field inside a block can be `symbol`, `text`, `rich_text`, `number`, `boolean`, `date`, `select`, `media`, `location` or `json`, and uses the write and read shapes on this page. [Blocks](/docs/concepts/blocks) has the full picture.

## Filtering and sorting by field type

The read API can filter and sort a list by a field's value. What a field takes depends on its type. The generated TypeScript type is shown alongside.

| Types | Filters | Sort | TypeScript |
| --- | --- | --- | --- |
| `symbol`, `text`, `slug`, `select`, `date` | Equals, `[ne]`, `[in]`, `[nin]`, `[exists]`, `[match]`, `[gt]`, `[gte]`, `[lt]`, `[lte]` | Yes | `string` |
| `number` | The same without `[match]` | Yes | `number` |
| `boolean` | Equals, `[ne]`, `[exists]` | Yes | `boolean` |
| `reference` | Equals, `[ne]`, `[in]`, `[nin]`, `[exists]`, by the linked entry's id | Yes | `MojimotoLink` or `null` |
| `references` | The same, meaning the list holds that entry | No | `MojimotoLink[]` |
| `media` | `[exists]` | No | `MojimotoMedia` or `null` |
| `rich_text` | `[exists]` | No | `unknown` |
| `location` | `[exists]` | No | `{ lat: number; lon: number }` or `null` |
| `json` | `[exists]` | No | `Record<string, unknown>` |
| `blocks` | `[exists]` | No | A union of the field's block types |

The [delivery API reference](/docs/api/delivery) explains each filter, and [Generated types](/docs/tools/generated-types) explains the TypeScript.

## Empty values

`null`, an empty string and an empty array all count as empty. A required field that is empty stops the entry being published. `false` and `0` are values, not empty.

Saving a draft replaces the entry's whole `data`, so a field you leave out is cleared. To clear a field on purpose, leave it out or write `null`.

A field that has never been written is missing from `data` on the read API, except that a media or reference field is `null` and a references or blocks field is `[]`.
