Data types
Metafields use data types to define the content that can be stored. Each data type has built-in format validation. Regardless of the data type, metafield values are passed and stored as strings. In theme templates, you can access metafields through the metafield object.
Base types
Base type metafields store text, numbers, dates, and measurements with units.
| Type | Description | Value type |
|---|---|---|
boolean | A boolean value (true or false). | boolean |
color | A hexadecimal color code. | string |
date | A date in ISO 8601 format without a time zone. | string |
date_time | A date and time in ISO 8601 format without a time zone. Greenwich Mean Time (GMT) is used by default. | string |
dimension | A numeric length value and unit. Valid units are:
| JSON object |
json | A JSON-serializable value, which can be an object, array, string, number, boolean value, or null. | JSON object |
link | A combination of text and a URL for storing link content. | JSON object |
money | A monetary amount with a currency code that matches the store currency. | JSON object |
multi_line_text_field | A multiline text field with a maximum size of 65 KB. | string |
number_decimal | A decimal number ranging from -9,999,999,999,999.999999999 to 9,999,999,999,999.999999999. | string |
number_integer | An integer ranging from -9,999,999,999,999 to 9,999,999,999,999. | integer |
rating | A rating within a specified range. The scale_min and scale_max validation parameters are required. | JSON object |
rich_text_field | A rich text field that supports headings, lists, links, bold text, and italic text. | JSON object |
single_line_text_field | A single-line text field with a maximum size of 65 KB. | string |
url | A URL that supports the following protocols: https, http, mailto, sms, and tel. | string |
volume | A numeric volume value and unit. Valid units are:
| JSON object |
weight | A numeric weight value and unit. Valid units are:
| JSON object |
Base type code examples
The following examples show the expected value format for each base type:
| Type | Example |
|---|---|
boolean | |
color | |
date | |
date_time | |
dimension | |
json | |
link | |
money | |
multi_line_text_field | |
number_decimal | |
number_integer | |
rating | |
rich_text_field | |
single_line_text_field | |
url | |
volume | |
weight | |
Reference types
Reference type metafields store references to store resources.
| Type | Description | Value type |
|---|---|---|
collection_reference | A reference to a product collection. | string |
file_reference | A reference to a file. | string |
metaobject_reference | A reference to a metaobject entry. | string |
page_reference | A reference to a page. | string |
product_reference | A reference to a product. | string |
variant_reference | A reference to a product variant. | string |
article_reference | A reference to an article. | string |
Reference type code examples
| Type | Example |
|---|---|
collection_reference | |
file_reference | |
metaobject_reference | |
page_reference | |
product_reference | |
variant_reference | |
article_reference | |
List types
List type metafields store multiple values in a single metafield. Values are represented as JSON arrays. Each list type metafield can contain up to 128 elements.
| Type | Description |
|---|---|
list.color | A list of hexadecimal color codes. |
list.collection_reference | A list of product collection references. |
list.date | A list of dates in ISO 8601 format. |
list.date_time | A list of dates and times in ISO 8601 format. |
list.dimension | A list of numeric length values and units. Valid units are:
|
list.file_reference | A list of file references. |
list.link | A list of text and URL combinations for storing multiple links. |
list.metaobject_reference | A list of metaobject entry references. |
list.number_decimal | A list of decimal numbers. |
list.number_integer | A list of integers. |
list.page_reference | A list of page references. |
list.article_reference | A list of article references. |
list.product_reference | A list of product references. |
list.rating | A list of ratings within a specified range. |
list.single_line_text_field | A list of single-line text fields. |
list.url | A list of URLs that support the https, http, mailto, sms, and tel protocols. |
list.variant_reference | A list of product variant references. |
list.volume | A list of numeric volume values and units. Valid units are:
|
list.weight | A list of numeric weight values and units. Valid units are:
|
List type code examples
| Type | Example |
|---|---|
list.color | |
list.collection_reference | |
list.date | |
list.date_time | |
list.dimension | |
list.file_reference | |
list.link | |
list.metaobject_reference | |
list.number_decimal | |
list.number_integer | |
list.page_reference | |
list.article_reference | |
list.product_reference | |
list.rating | |
list.single_line_text_field | |
list.url | |
list.variant_reference | |
list.volume | |
list.weight | |
Rich text format
The rich_text_field type accepts JSON objects with the following structure:
{
"type": "root",
"children": [
{
"type": "paragraph",
"children": [
{
"type": "text",
"value": "This is regular text.",
"bold": true,
"italic": true
},
{
"type": "link",
"url": "https://example.com",
"title": "Example link",
"children": [
{
"type": "text",
"value": "Learn more",
"bold": true
}
]
}
]
}
]
}
Bold and italic
Text nodes use bold and italic to set text styles. The fields are described as follows:
| Field | Required | Description |
|---|---|---|
type | Yes | Fixed as text. |
value | Yes | The content of the text node. |
bold | No | Whether the text is bold. The default value is false. |
italic | No | Whether the text is italic. The default value is false. |
Example
{
"type": "root",
"children": [
{
"type": "paragraph",
"children": [
{
"type": "text",
"value": "This text is bold and italic.",
"bold": true,
"italic": true
}
]
}
]
}
Headings
The fields of a heading node are described as follows:
| Field | Required | Description |
|---|---|---|
type | Yes | Fixed as heading. |
level | Yes | The heading level. Supported values range from 1 to 6. |
children | Yes | An array of text nodes. |
Example
{
"type": "root",
"children": [
{
"type": "heading",
"level": 2,
"children": [
{
"type": "text",
"value": "This is a level 2 heading"
}
]
}
]
}
Links
The fields of a link node are described as follows:
| Field | Required | Description |
|---|---|---|
type | Yes | Fixed as link. |
url | Yes | The destination URL of the link. |
title | No | The link title, which can be used for accessibility and search engine optimization (SEO). |
target | No | The target for opening the link. For example, _blank opens the link in a new tab. |
children | Yes | An array of text nodes. |
Example
{
"type": "root",
"children": [
{
"type": "paragraph",
"children": [
{
"type": "link",
"url": "https://example.com",
"title": "Link to example.com",
"target": "_blank",
"children": [
{
"type": "text",
"value": "View details"
}
]
}
]
}
]
}
Lists
The fields of list nodes and list item nodes are described as follows.
List node:
| Field | Required | Description |
|---|---|---|
type | Yes | Fixed as list. |
listType | Yes | The list type. Supported values are ordered and unordered. |
children | Yes | An array of nodes with type set to list-item. |
List item node:
| Field | Required | Description |
|---|---|---|
type | Yes | Fixed as list-item. |
children | Yes | An array of text nodes. |
Example
{
"type": "root",
"children": [
{
"type": "list",
"listType": "unordered",
"children": [
{
"type": "list-item",
"children": [
{
"type": "text",
"value": "First item"
}
]
},
{
"type": "list-item",
"children": [
{
"type": "text",
"value": "Second item"
}
]
}
]
}
]
}