How can i put a json body in a environnement variable

I try to create a environnement variable containing this:

{
  "type":"1234",
  "project_id": "1234",
  "private_key_id": "1234",
  "private_key": "1234564789",
  "client_email": "iam.gserviceaccount.com",
  "client_id": "1072",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://oauth2.googleapis.com/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com",
  "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadatam"
}

I don’t want to create the env variable "auth_url", "token_url" etc… I would like to create a variable that would contain all these elements.

I saw on the internet that we could do a $var = {"key", "index, ….}

but it doesn’t work:

$GOOGLE_APPLICATION_CREDENTIALS={"type": "service_account",  "project_id": "blabla"}

If someone has a solution.

Thanks for yours answers

>Solution :

Yes you can, but you need to put the whole value as a string, so the starting curly braces {} must be inside of the string as well. I mean you need to put whole json inside ' '.

GOOGLE_APPLICATION_CREDENTIALS='{"type": "service_account",  "project_id": "blabla"}'

However, then in your app you will need to parse that string. For example, in node.js it would be const creds = JSON.parse(process.env.GOOGLE_APPLICATION_CREDENTIALS);
Or use corresponding function of the platform/language you use in your app.

Leave a Reply