ssk
ssk

Reputation: 9255

Localization in bash for the config file

I have a config json file. Here is an example:

{
    "tls": true,
    "port": 443,
    "room_server": "http:/prod.testwebsite.com/",
    "cert_path": "/test/prod/cert.pem"
}

I would like to set room_server/cert_path according to the machine i.e., http:/dev.testwebsite.com/ vs http:/prod.testwebsite.com/ and /test/dev/cert.pem vs /test/prod/cert.pem.

How to accomplish this substitution in bash?

Upvotes: 0

Views: 46

Answers (1)

chepner
chepner

Reputation: 531235

Use a tool like jq to modify JSON.

$ jq '.room_server="http:/dev.testwebsite.com" | .cert_path="/test/dev/cert.pem"' config.json
{
  "tls": true,
  "port": 443,
  "room_server": "http:/dev.testwebsite.com",
  "cert_path": "/test/dev/cert.pem"
}

Upvotes: 1

Related Questions