Unlock seamless workflows and faster delivery with our latest releases- get the details

Is there any way to set the Project ID and Dataset in the sanity.json file via .env?

5 replies
Last updated: May 9, 2022
Is there any way to set the project id and dataset in the sanity.json file via .env?
May 9, 2022, 7:28 AM
Mmh, not really since JSON is static by definition. What is your use case? 🙂
May 9, 2022, 7:34 AM
you can’t set them there, but you can override them

https://www.sanity.io/docs/studio-environment-variables#cc239c4841f0
SANITY_STUDIO_API_PROJECT_ID - Sets the project ID for the current build. This overrides the sanity.json property api.projectId. This environment variable has higher precedence than any env configuration defined in sanity.json.

SANITY_STUDIO_API_DATASET - Sets the dataset for the current build. This overrides the sanity.json property api.dataset. This environment variable has higher precedence than any env configuration defined in sanity.json.
May 9, 2022, 8:00 AM
So I guess you could avoid setting them in
sanity.json
, and pass them as environment variables to your Studio if that works?
May 9, 2022, 8:13 AM
yeah i just set projectId to null usually

  "api": {
    "projectId": null
May 9, 2022, 8:15 AM
Great, thanks!
Use case is a wierd "multisite" thing where different datasets will be different sites
May 9, 2022, 8:40 AM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?