Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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, ….}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading