Contentstack JSON Data Formats: Modular Blocks Fields

This blog post, part of a series about JSON data formats in the Contentstack SaaS headless CMS, describes how Contentstack represents data stored in modular blocks fields as JSON.

Contentstack modular blocks fields contain blocks of data. In an entry, a modular blocks field may contain any number of blocks of JSON having different and possibly repeated structures.

Within modular blocks fields, individual blocks function much like nested group fields or global fields in that they define a container for nested fields. The key in the JSON that identifies the modular blocks field contains a list of blocks, where the key for each block indicates its type and hence the fields that it contains, as specified in the content type or global field that defines the modular blocks field.

For example, a modular blocks field allows two types of blocks. A block with ID dateblock contains a single-line text field and a date field. Another block with ID selectblock contains a single-line text field and a select list that allows multiple selections. A sample JSON representation of one date block and two select blocks is as follows.

"modularblocksfieldid": [
{
    "dateblock": {
        "single_line": "First Single Line Textbox Value",
        "date": "2021-11-29T14:26:08.000Z",
        "_metadata": {
            "uid": "csa9302ab45768b845"
        }
    }
},
{
    "selectblock": {
        "single_line": "Second Single Line Textbox Value",
        "select": [
            "second",
            "third"
        ],
        "_metadata": {
            "uid": "cs67634232513ee1b9"
        }
    }
},
{
    "selectblock": {
        "single_line": "Third Single Line Textbox",
        "select": [
            "first",
            "third"
        ],
        "_metadata": {
            "uid": "csdc3e7019d4241ed9"
        }
    }
}
],
//…

The default JSON structure generated from the field structure is logical and includes identifiers that you control. Other than the _metadata key for unique identifiers that Contentstack includes to support referencing and reuse of blocks and which can be stripped, excluding markdown, JSON, or other values that require processing, the default JSON representation of modular blocks field lacks vendor-specific formats and may not require normalization before use by other systems, which would otherwise be a form of coupling to avoid.

5 thoughts on “Contentstack JSON Data Formats: Modular Blocks Fields

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: