How to add rich text block inside array of structured content in Sanity?
I can see the issue! You're trying to nest an array inside another array, which causes this error in Sanity. The problem is that your textBlock is defined as type: "array", and you're trying to use it inside another array field.
The solution is to define textBlock as an object type, not an array type:
export default {
name: "textBlock",
title: "Text Block",
type: "object", // Changed from "array" to "object"
fields: [
{
name: "content",
title: "Content",
type: "array",
of: [{ type: "block" }],
}
]
};Now your main content array will work properly:
{
title: "Content",
name: "content",
type: "array",
group: "countryInfo",
of: [
{ type: "textBlock" }, // This now references an object, not an array
{ type: "image" },
{ type: "speedTest" },
{ type: "thePricingTable" },
],
}Why this works: In Sanity, when you have an array field, the items in the of array can be either:
- Simple types like
block,image,string - Object types (which can themselves contain arrays)
But you cannot directly nest arrays within arrays. By making textBlock an object type that contains an array field, you follow Sanity's schema structure correctly.
Alternative approach: If you just want rich text directly in your content array without the extra wrapper, you can simply use:
{
title: "Content",
name: "content",
type: "array",
of: [
{ type: "block" }, // Rich text directly
{ type: "image" },
{ type: "speedTest" },
{ type: "thePricingTable" },
],
}This gives you Portable Text rich text editing capabilities mixed with your custom block types, which is the standard pattern for Block Content in Sanity.
Show original thread7 replies
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.