
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeYes, absolutely! You can migrate data from one field structure to another without losing your content. Sanity provides migration tooling specifically for this kind of schema restructuring.
For your specific case (moving from an object with an images array to just an array of images), you can use the defineMigration API to copy the data from the nested field to a new field structure.
Here's how you'd approach this:
1. Create a migration script:
npx sanity@latest migration create "migrate-images-field"2. Write the migration logic:
import {defineMigration, at, setIfMissing, unset} from 'sanity/migrate'
export default defineMigration({
title: 'Migrate images from object to array',
documentTypes: ["yourDocumentType"], // replace with your actual document type
migrate: {
document(doc, context) {
// Only migrate if the old structure exists
if (!doc.images?.images) {
return []
}
return [
// Copy the images array to the new structure
at('newImages', setIfMissing(doc.images.images)),
// Optionally remove the old field after confirming data is copied
// at('images', unset())
]
}
}
})3. Test with a dry run first:
sanity migration run migrate-images-fieldThis runs without making changes so you can verify everything looks correct.
4. Execute the migration:
sanity migration run migrate-images-field --dataset <your-dataset>Important tips:
You can also update your schema at the same time, or before/after the migration depending on your workflow. The Content Migration documentation recommends an incremental approach - start simple, verify, then add complexity.
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