How to switch datasets in Sanity without getting errors in Studio?

4 replies
Last updated: Jun 9, 2020
hey all... how do i switch datasets? now that my schema is 99% setup i wanted to start working from an empty dataset for entering production content.
i went into
sanity.json
and set the dataset to my new one, but now i'm getting a bunch of errors in studio
AI Update

Good news - you're actually on the right track, but it sounds like you're working with an older Studio v2 setup (which used sanity.json). If you're seeing errors after changing the dataset, here's what's likely happening and how to fix it:

If you're on Studio v3 (current version)

Your dataset configuration should be in sanity.config.js (or .ts), not sanity.json. The sanity.config.js file is where all Studio configuration lives in v3. Here's what you need to do:

  1. Update your sanity.config.js:
import { defineConfig } from 'sanity'

export default defineConfig({
  projectId: 'your-project-id',
  dataset: 'your-new-dataset-name', // Change this to your new dataset
  // ... rest of your config
})
  1. Make sure the dataset exists: Go to your Sanity project dashboard and verify the new dataset has been created. You may need to create it first if it doesn't exist.

  2. Deploy your schema to the new dataset: Run this command to ensure your schema is available in the new dataset:

sanity schema deploy

This is especially important if you're using newer features like Agent Actions or if you have any validation rules that depend on the schema being deployed.

If you're still on Studio v2

Studio v2 reached end-of-life in December 2023, so I'd strongly recommend migrating to v3. But if you need a quick fix for v2, check that your sanity.json has the correct dataset name under the api section.

Common errors after switching datasets

The errors you're seeing are likely because:

  • The new dataset doesn't have your schema deployed yet
  • You have validation rules or initial value templates that reference data from the old dataset
  • Permissions haven't been set up for the new dataset

After updating the config and deploying the schema, restart your dev server (sanity dev or npm run dev) and the errors should clear up!

Show original thread
4 replies
here's the error in the browser

SyntaxError: Unexpected token / in JSON at position 107
    at JSON.parse (<anonymous>)
    at parseManifest (/Users/bflory/Development/yamamoto/goyamamoto/backend/node_modules/@sanity/resolver/lib/readManifest.js:44:29)
    at /Users/bflory/Development/yamamoto/goyamamoto/backend/node_modules/@sanity/resolver/lib/readManifest.js:68:18
also i can't switch back to the previous dataset now either
console error when i run
sanity start


Error occured trying to resolve project root:
Unexpected token / in JSON at position 131
SOLVED: for anyone looking in the future, I had commented out the old dataset, and added the new one...
can't believe i've not run across this before, but apparently you can't use commenting in JSON

Sanity – Build the way you think, not the way your CMS thinks

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.

Was this answer helpful?