
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeBased on the documentation, _key is unique only within its containing array, not across the entire document type.
The documentation on _key specifically states that "_key values only need to be unique within their containing array." This is different from document IDs (_id), which must be unique across your entire dataset.
So to clarify the scope of uniqueness:
_key must be unique among items in that specific array_key value_key valuesFor example, this is perfectly valid:
{
_id: "doc1",
arrayA: [
{ _key: "abc123", title: "Item 1" },
{ _key: "def456", title: "Item 2" }
],
arrayB: [
{ _key: "abc123", title: "Different Item" } // Same _key as in arrayA - totally fine!
]
}When you're creating array items programmatically, you just need to ensure uniqueness within that specific array. Using a UUID generator (like the uuid package) is the standard approach to avoid collisions within the array you're working with.
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.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store