Skip to content

Instantly share code, notes, and snippets.

@bonovoxly
Created May 10, 2024 14:13
Show Gist options
  • Save bonovoxly/6c3069576953ffe85b1bff2e8da79697 to your computer and use it in GitHub Desktop.
Save bonovoxly/6c3069576953ffe85b1bff2e8da79697 to your computer and use it in GitHub Desktop.
boto3 decimal thing
# https://github.com/boto/boto3/issues/369
# fixes decimal issues
def replace_decimals(obj):
if isinstance(obj, list):
for i in range(len(obj)):
obj[i] = replace_decimals(obj[i])
return obj
elif isinstance(obj, dict):
for k in obj.keys():
obj[k] = replace_decimals(obj[k])
return obj
elif isinstance(obj, Decimal):
if obj % 1 == 0:
return int(obj)
else:
return float(obj)
else:
return obj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment