Skip to content

Instantly share code, notes, and snippets.

@junftnt
Forked from kr/jsonenv
Created March 30, 2020 18:34
Show Gist options
  • Select an option

  • Save junftnt/18afd354097d65bb57e23c163f30c8d8 to your computer and use it in GitHub Desktop.

Select an option

Save junftnt/18afd354097d65bb57e23c163f30c8d8 to your computer and use it in GitHub Desktop.
convert a json dictionary into environment variables
#!/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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment