Why is title an array?

Hi i have added a title field it looks like an pure object for me but i just get an array back

heading is just the title field

{
   "heading":[
      {
         "type":"heading1",
         "text":"Faq",
         "spans":[
         ]
      }
   ],
   "body":[
      {
         "slice_type":"faq",
         "slice_label":null,
         "items":[
            "Array"
         ],
         "primary":{

         }
      }
   ]
}

//e i have no Problems but i just wonder why

Hi @cannap,

This is a good question, thanks for asking. The Title field is a specific type of Rich Text field, so it works the same way under the hood that a Rich Text field does. A Rich Text field allows for multiple blocks of content where you can select different options, so the output is an array of these blocks. With a Title field, you can only add a single block of content.

So I understand that it might seem weird to have the output be an array, but that is only because the Title field is a specific type of Rich Text field. This way, the Title field can use the same helper functions as a Rich Text field (RichText.asHtml, RichText.asText, RichText.render). Here is the documentation for templating a Rich Text or Title field with Javascript.

I hope everything makes more sense now!

1 Like

You can use the key text field instead, that just returns plaintext. It’s what I use when I don’t need rich text in my headings.

1 Like