How to Insert Environment Variables in a JSON Config

8 replies
Last updated: Sep 29, 2021
How do you insert environment variables in a .json config?
I think we need some more context here… The value of the env var or the name of it to be resolved later?
One of the main things about using env vars is that they are not stored on disk.
For development I wanted to put it in a
.env
file
I just don't want to store it in the .json file
Hey Max! What are you looking to put into an env file? There's some information on using env vars here , but I could possibly give you more specific advice if I knew more about the use case!
I don't want the tokens in a public repo
You'll have to use one of the methods described here if you're trying to obscure your tokens.
How do I do this with the .json config? Is there something I can do to add environment variables to a config?
config/@sanity/google-maps-input.json
has a key
apiKey
which I want it to be a environment variable.

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?