-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjson.json
More file actions
33 lines (22 loc) · 696 Bytes
/
json.json
File metadata and controls
33 lines (22 loc) · 696 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
Given x.json:
{
"URL": "https://foo:[email protected]/",
"OTHER": "foo \" bar 'baz'"
}
This produces:
$ ./jsonenv <x.json
URL=https://foo:[email protected]/ export URL;
OTHER='foo " bar '"'"'baz'"'"'' export OTHER;
You can use it with the heroku api like this:
$ eval "$(curl -sn https://api.heroku.com/apps/myapp/config_vars|jsonenv)"
to use the config vars from myapp in your local shell.
#!/usr/bin/env python
# jsonenv reads a json object as input and produces
# escaped shell commands for setting environment vars
import json
import pipes
import sys
for k, v in json.load(sys.stdin).items():
k = pipes.quote(k)
v = pipes.quote(v)
print "%s=%s export %s;" % (k, v, k)