
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeI totally get it—the docs can be a bit overwhelming when you're just trying to get data into Sanity! Since you have 280+ objects with regular structure that almost matches your schema, you've got a few solid approaches:
The CLI migration tool is probably your best bet here. It's designed exactly for this scenario and gives you real-time feedback as you work.
Quick start:
npx sanity@latest migration createThis creates a migration script where you can transform your data. Here's a simple example:
import {defineMigration, at, set} from 'sanity/migrate'
export default defineMigration({
title: 'Import my 280 objects',
documentTypes: ["yourDocumentType"],
migrate: {
async document(doc, context) {
// Your transformation logic here
return [
at('fieldName', set(transformedValue)),
// ... more field mappings
]
}
}
})Why this is great:
If your data transformation is straightforward, you could also generate an NDJSON file and use the CLI import command. NDJSON is just newline-delimited JSON—one document per line.
Your workflow would be:
.ndjson (one JSON object per line)sanity dataset import yourfile.ndjson productionImportant flags:
--replace - Replaces existing documents with matching IDs--missing - Only imports documents that don't exist yet--allow-failing-assets - Continues if some assets fail to uploadEach document needs:
{"_id": "unique-id", "_type": "yourType", "title": "Something", ...}The _id and _type fields are required. The _id should be unique and deterministic (so you can re-run imports safely).
Start simple: Don't try to map everything perfectly on the first run. Get the basic structure working with just IDs and titles, then add complexity incrementally. This makes debugging way easier.
Handle missing data: Your source data might have gaps. Use optional chaining and fallbacks:
at('description', set(sourceObj.description || 'No description'))For arrays with objects: Remember that objects in arrays need a _key field (unique identifier). You can generate these with a utility like uuid:
items: sourceArray.map(item => ({
_key: uuid(),
...item
}))Given that you mentioned the fields "almost match," I'd lean toward the migration tool—it'll catch any mismatches before you commit, and you can iterate on the transformation logic easily.
Hope this helps! Feel free to share more about your specific data structure if you want more targeted advice.
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 backend


The only platform powering content operations


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