Adding array to block element in Sanity (multidimensional array error)
You're right that you've probably done something similar before! The error "multidimensional arrays are not currently supported by Sanity" appears when you try to have an array directly inside another array, but there's a common workaround that you've likely used.
The Issue:
Sanity doesn't support arrays directly nested in arrays (like array of array of strings). So if you're trying to add an array field to a block element in Portable Text, you'll hit this limitation.
The Solution: The workaround is to wrap your inner array in an object type. This is explained in Sanity's documentation on this error.
Here's a practical example for a common use case - representing rows and columns:
export default createSchema({
name: 'default',
types: schemaTypes.concat([
{
name: 'row',
title: 'Row',
type: 'object',
fields: [
{
name: 'columns',
title: 'Columns',
type: 'array',
of: [{type: 'string'}]
}
]
},
{
name: 'someDocumentType',
title: 'Some document type',
type: 'document',
fields: [
{
name: 'rows',
title: 'Rows',
type: 'array',
of: [{type: 'row'}]
}
]
}
])
})For Block Content Specifically:
If you want to add a custom block to Portable Text that contains an array, you'd define it as an object type and then include it in your block content's of array:
{
name: 'content',
type: 'array',
of: [
{type: 'block'},
{
type: 'object',
name: 'customBlock',
fields: [
{
name: 'items',
type: 'array',
of: [{type: 'string'}]
}
]
}
]
}The key is that while you can't have array → array, you can have array → object → array, which accomplishes the same goal! This is the pattern you've likely used before when working with nested arrays in Sanity schemas.
Show original thread1 reply
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.