Skip to content

Instantly share code, notes, and snippets.

@vec715
Created June 29, 2023 21:13
Show Gist options
  • Save vec715/2e4a75aeeb5fb0c522514bc0c42c7454 to your computer and use it in GitHub Desktop.
Save vec715/2e4a75aeeb5fb0c522514bc0c42c7454 to your computer and use it in GitHub Desktop.
Parse AWS JSON ENV into .env format
import json
def aws_json_to_env(input_json):
with open('.env', 'w') as file:
for item in input_json:
try:
file.write(f'{item["name"]}={item["value"]}\n')
except TypeError:
print(f"Expected a dictionary, but got: {item}")
except KeyError:
print(f"Expected keys 'name' and 'value' in dictionary, but got: {item}")
# Test the function
json_input = [
{
"name": "foo",
"value": "bar"
}
]
aws_json_to_env(json_input)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment