Created
February 23, 2018 09:30
-
-
Save smoothml/59fb228580746e0535df6caf5ea6892b to your computer and use it in GitHub Desktop.
2018-02-23 Serverless computing reformat_json.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def reformat_json(response): | |
# rearrange the response to not be nested | |
# i.e. {"rates": {"EUR": 1.2}} -> {"EUR": 1.2} | |
rates = response.pop("rates") | |
response.update(rates) | |
# update response to DynamoDB's required format | |
response_updated = {} | |
for key, val in response.items(): | |
# date and base fields are strings (DynamoDB has no date type) whereas everything else is a | |
# number | |
if key == "date" or key == "base": | |
val_type = "S" | |
else: | |
val_type = "N" | |
val = str(val) | |
response_updated[key] = {val_type: val} | |
return response_updated |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment