
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeGood news! GROQ preserves array order by default when you dereference references using []->. The order you see in the Studio should be maintained in your query results.
Based on this exact question from the Sanity community, the solution is straightforward:
*[_type == "gallery"]{
images[]->
}This simple syntax grabs the referenced images from your gallery document and automatically preserves the order you've set in the Studio.
Common mistake that breaks ordering:
If you're querying using back-references (using references() to find documents that point to your array items), the order won't be preserved because you're essentially doing a reverse lookup:
// ❌ This won't preserve your Studio order
"images": *[_type == "image" && references(^._id)]{
url
}Instead, use the direct array dereference:
// ✅ This preserves order
images[]->{
"imageUrl": asset->url,
altText,
caption
}If you need to preserve _key along with the dereferenced content:
Sometimes you need both the original array metadata (like _key) and the dereferenced document. Use this pattern:
images[]{
_key,
...(@->)
}This explicitly includes the _key property before spreading the dereferenced content, which can be useful for React keys or tracking individual items.
Troubleshooting checklist:
[]-> not a reverse lookup with references()The bottom line: Simple dereferencing with images[]-> should "just work" and maintain your Studio order automatically!
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