
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeYes! While you can't directly use environment variables inside the sanity.json file (since JSON is static), you can override the values using special environment variables.
The Sanity CLI recognizes these specific environment variables that take precedence over what's in sanity.json:
SANITY_STUDIO_API_PROJECT_ID - Overrides the api.projectId propertySANITY_STUDIO_API_DATASET - Overrides the api.dataset propertyAccording to the Studio environment variables documentation, these environment variables have higher precedence than any configuration defined in sanity.json.
A common pattern is to set projectId to null in your sanity.json:
{
"api": {
"projectId": null,
"dataset": "production"
}
}Then define the values in your .env file:
SANITY_STUDIO_API_PROJECT_ID=your-project-id
SANITY_STUDIO_API_DATASET=productionThis approach is particularly useful for multi-site setups where different datasets represent different sites, or when you want to keep project configuration out of version control during development.
Important note: This is specifically for Sanity Studio v2. If you're using Studio v3+, configuration is handled differently through the sanity.config.js or sanity.config.ts file, where you can directly reference environment variables in JavaScript/TypeScript using process.env.SANITY_STUDIO_API_PROJECT_ID.
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