Start page / Enhanced JSON support / Single expression page rendering

Standardized JSON output

Contents

JSON (JavaScript Object Notation, see also json.org) is a popular standard data exchange format.

FirstSpirit supports the output of pages as JSON documents with one single CMS_VALUE expression: $CMS_VALUE(json(#this))$

Output of values

Values are output according to the JSON specification, i.e., boolean as true or false, numbers with a period '.' as a decimal separator, and a missing value is displayed as null. Certain characters in character strings are protected by a backslash '\'. Date values are written as strings in the ISO 8601 standard, which is also commonly used in JavaScript:

"2019-05-28T10:50:47.684Z"

Objects are enclosed in curly brackets '{}' and lists (arrays) in square brackets '[]'.

Structure

The JSON output of a page includes the page, its content areas and sections, as well as the content data, if available. Every page, content, and section element is displayed as a separate JSON object within a JSON object hierarchy. Each page root object contains its content areas (“bodies”) as a JSON array in the children attribute and each content area in turn contains its section objects (“sections”) as a JSON array in the children attribute.

For pages and sections, the data is output as a JSON object in the formData attribute. The formData JSON object contains the data of the input components as key value pairs, where the name of the input component is the key and the content of the input component is a JSON object. As can be seen in the example, these value objects each have the attributes fsType, name and value.

Depending on the type of the input component, the value of a character string can be a number, a boolean variable (true/false), or another JSON representation of a FormField value.

Example:

{
"fsType": "PageRef",
"name": "pt_components",
"displayName": "pt_components",
"identifier": "1c2c3d4b-2896-43ab-a2ec-e2fbdb0d8b1d",
"uid": "pt_components",
"uidType": "SITESTORE_LEAF",
"metaFormData": {

},
"page": {
"fsType": "Page",
"name": "pt_components",
"displayName": "pt_components",
"identifier": "d658ed13-3318-4eb7-a442-f0b893270ed0",
"translated": false,
"uid": "pt_components",
"uidType": "PAGESTORE",
"template": {
"fsType": "PageTemplate",
"name": "pt_components",
"displayName": "pt_components",
"identifier": "481d928b-cd65-42b3-9799-1e1bb6d63c92",
"uid": "pt_components",
"uidType": "TEMPLATESTORE"
},
"formData": {
"st_headline": {
"fsType": "CMS_INPUT_TEXT",
"name": "st_headline",
"value": "Text der Seite"
}
},
"metaFormData": {

},
"children": [
{
"fsType": "Body",
"name": "content",
"identifier": "f592ef7b-9ae3-4c03-ac46-f44766547e30",
"children": [
{
"fsType": "Section",
"name": "text_absatz",
"displayName": "Text_Absatz",
"identifier": "c4c29467-f948-484a-b09f-72870ec66b96",
"template": {
"fsType": "SectionTemplate",
"name": "Text_Absatz",
"displayName": "Text_Absatz",
"identifier": "fc152884-1f75-4028-8979-19e549e75945",
"uid": "text_absatz",
"uidType": "TEMPLATESTORE"
},
"formData": {
"st_input_text": {
"fsType": "CMS_INPUT_TEXT",
"name": "st_input_text",
"value": "Text des Absatzes "
}
}
}
]
}
]
}
}

Output of sections

If the #global.json.sectionTemplateRendering JSON configuration is “true”, section templates are evaluated for sections individually, instead of being generated automatically during default output.

If the #global.json.sectionTemplateRendering JSON configuration is “false”, section templates are ignored and the default output format is used with the attributes described in the previous paragraph.

If sectionTemplateRendering is used, the default output can be triggered within the section template by:

$CMS_VALUE(json(#this))$ 

If a template has no content, an empty JSON object "{}" is displayed as a fallback to ensure a valid JSON output is created.

Manual output of content areas

If the standard expression $CMS_VALUE(json(#this))$ is not to be used, a separate JSON output can be created for the page. If sectionTemplateRendering in the JSON configuration is “true”, then the content of all sections of a content area can be displayed as a JSON array using this template code:

$CMS_VALUE(json(#global.page.body("<bodyname>")))$

It must be ensured that every section generates a valid JSON element. The elements are combined automatically.

Output of table templates

If table templates (or content projections) are used,

$CMS_VALUE(json(#this))$

will output every dataset that is valid for output as a JSON object.

If the “Data” area of the Site Store is configured such that three entries are displayed (see Settings at page reference level (→Documentation FirstSpirit SiteArchitect)), then three JSON objects will be output in the children array of the higher-level content area (body).

Every section instance generated from a dataset can be modified in the same way as any other JSON section, e.g., using the json API:

$CMS_VALUE(json(#this).set("my_attr", "my_value"))$ 

The variables #row, #cs, and form variables are not available in the context of json/tabletemplate.

If circular references are identified, a corresponding reference to the original element is simply output. This means that datasets found multiple times in the same stack are only output as a reference from the second time they occur.
Example:

"fsType": "CircularReference"

© 2005 - 2024 Crownpeak Technology GmbH | All rights reserved. | FirstSpirit 2024.3 | Data privacy