Index
Edit

Object

Objects describe JSON objects that can be embedded inside documents. They

The object type is the bread and butter of your data model. You use it to define custom types that has fields of strings, numbers, arrays as well as other object types.

Note: By default, object types can not be represented as standalone documents in the data store. If you want to define an object type that you'd like to be represented as a document, you should define it using the document type instead.

PROPERTIES

  • fields: array - The fields of this object. At least one field is required.
  • fieldsetsarray - A list of fieldsets that fields may belong to. See below.
  • preview: object - A preview config for this object type.

Fields

Fields are what gives object its structure. Every field must have a name and a type. You may specify the properties and options that are supported for the given type, e.g.:

{
  title: 'Address',
  name: 'address',
type: 'object',
fields: [
{name: 'street', type: 'string', title: 'Street name'},
{name: 'streetNo', type: 'string', title: 'Street number'},
{name: 'city', type: 'string', title: 'City'}
] }

Supported field properties:

In addition to the properties defined by the field type, these field properties are also supported:

  • name: string (required) - The field name. This will be the key in the data record.
  • type: a valid schema type (required) - This will be the type of the value in the data record.
  • hidden: boolean - If set to true, this field will be hidden in the content studio.
  • readOnly: boolean - If set to true, this field will not be editable in the content studio.
  • requiredboolean - If set to true, this field will not be publishable if the value is missing. Note: validation is not yet supported yet, but on our roadmap.
  • description: string - a human readable description of the purpose of the field. Typically displayed to the editors as part of the field component.

Full example

Lets say you would like to add an address field on a movie screening. It would make sense to define a re-usable address type that also can be used elsewhere, but it doesn't make much sense to create standalone address documents, so this makes a great candidate for an object type. Lets start by adding an address type to our schema:

{
  title: 'Address',
  name: 'address',
  type: 'object',
  fields: [
    {name: 'street', type: 'string', title: 'Street name'},
    {name: 'streetNo', type: 'string', title: 'Street number'},
    {name: 'city', type: 'string', title: 'City'}
  ]
}

Once its added to the schema, it can be used as the type of other fields, so lets use it in our screening:

{
  title: 'Screening',
  name: 'screening',
  type: 'document',
  fields: [
    // ... 
      {
      name: 'address',
      title: 'Cinema address',
type: 'address'
} // ... ] }

Example output data

{
  "_type": "screening",
  "_id": "2106a34f-315f-44bc-929b-bf8e9a3eba0d",
  "title": "Welcome to our premiere of Valerian and the City of a Thousand Planets!",
  //...
  "address": {
    "_type": "address",
    "street": "Dronningens gate",
    "streetNo": "16",
    "city": "Oslo"
  }
  //...
}

Additional field options

Sometimes you may have fields which are not meant to be exposed to the editors through the studio, but are populated by backend services or scripts. By setting the hidden property to true, you can make sure that the field is still included in the schema but not displayed in the studio. Example:

{
  title: 'Movie',
  name: 'movie',
  type: 'document',
  fields: [
    // ... other fields
    {
      title: 'Last synchronized',
      name: 'lastSynced',
      description: 'Timestamp the movie was last synced with external service. Not shown in studio.',
      type: 'date',
hidden: true
} ] }

Fieldsets

Sometimes it makes sense to group a set of fields into a fieldset:

{
  type: 'object',
fieldsets: [
{name: 'social', title: 'Social media handles'}
],
fields: [ { name: 'name', title: 'String', type: 'string' }, { name: 'twitter', title: 'Twitter', type: 'string',
fieldset: 'social'
}, { name: 'instagram', title: 'Instagram', type: 'string',
fieldset: 'social'
}, { name: 'facebook', title: 'Facebook', type: 'string',
fieldset: 'social'
} ] }

Here, the fields that are associated with the social fieldset, will be grouped together in the content studio:

But the values will appear at the same level as the name field in the actual data record: e.g.

{
  "name": "Somebody",
  "twitter": "@somebody",
  "instagram": "@somebody",
  "facebook": "somebody"
}

Previous: DocumentNext: String