PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, November 5, 2022

[FIXED] How can i put a json body in a environnement variable

 November 05, 2022     environment-variables, json, shell     No comments   

Issue

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.



Answered By - Artem Arkhipov
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing