How to Wrap Nested Arrays in Objects

4 replies
Last updated: Jul 16, 2020
I'm reading about this limitation with
array
types

Due to a limitation in the data store, arrays may not currently contain arrays. Wrap nested arrays in objects.
Does anyone have an example of wrapping nested arrays in objects? I'm not quite sure I understand how that would be setup.
Jul 16, 2020, 3:30 PM
Figured it out! This ties back to my question from yesterday
Since you can't nest arrays within arrays, I needed to wrap things with an extra layer to get the "page builder" effect I was looking for.
Jul 16, 2020, 4:14 PM
First, I created this schema which has the types I want to allow in my page builder
export default {
	name: 'clusterItems',
	type: 'array',
	title: 'Cluster Items',
	of: [
		{
			type: 'image'
		},
		{
			type: 'video'
		},
		{
			type: 'textContent'
		}
	]
};
Jul 16, 2020, 4:15 PM
Then I created this schema which I use in the actual editor

export default {
	name: 'cluster',
	type: 'object',
	title: 'Cluster',
	fields: [
		{
			name: 'items',
			type: 'clusterItems',
			title: 'Items'
		}
	]
};
Jul 16, 2020, 4:15 PM
Thanks for sharing back the examples Mark, really appreciated 👍
Jul 16, 2020, 7:01 PM

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.

Was this answer helpful?