Array contains multiple types that resolve to the same JSON type
This warning appears when you have an array type where multiple members resolve to the same underlying JSON type (for example, both string and text resolve to JSON type "string"). When Sanity stores array data, it uses the JSON type to serialize values. If multiple array members share the same JSON type, Sanity cannot distinguish between them at runtime. For example, if an array allows both string and text items, there's no way to know which type a given string value was originally intended to be when reading the data back.
The warning names the JSON type and the conflicting array members. For the example schema in this article, it reads: Array cannot contain multiple members with JSON type "string" ("heading" and "paragraph") as there is no way to distinguish between them
Example of problematic schema
defineField({
name: 'content',
type: 'array',
of: [
{type: 'string', name: 'heading'},
{type: 'text', name: 'paragraph'}, // Both resolve to JSON "string"
],
})Both string and text (as well as url and email) resolve to the JSON type "string". This means we have no way to tell them apart when the document is read.
How to fix
You have two options:
Use one primitive type per JSON type
If you only need one string-based type in your array, remove the duplicate:
defineField({
name: 'content',
type: 'array',
of: [
{type: 'string'},
],
})Choose this option when every item in the array can use the same input. Removing text in this example also removes its multiline input.
Wrap primitives in object types
If you need different string-based inputs with different behaviors, wrap them in named object types:
defineField({
name: 'content',
type: 'array',
of: [
{
type: 'object',
name: 'heading',
title: 'Heading',
fields: [{name: 'value', type: 'string'}],
},
{
type: 'object',
name: 'paragraph',
title: 'Paragraph',
fields: [{name: 'value', type: 'text'}],
},
],
})This gives each item a distinct _type property that Sanity can use to distinguish between them.
Choose this option when the array needs more than one string-based input. If documents already contain items for this array, they're stored as plain strings. After you change the schema, Sanity Studio shows an Invalid list values error on the field until you migrate those items to the new object shape.