Skip to content

Instantly share code, notes, and snippets.

@JamieCressey
Last active June 30, 2021 11:49
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save JamieCressey/94969418492f5a05b188e63954a23386 to your computer and use it in GitHub Desktop.
Save JamieCressey/94969418492f5a05b188e63954a23386 to your computer and use it in GitHub Desktop.
Coverts a Python Boto3 DynamoDB item to a standard dictionary
def parse_dynamo_item(item):
resp = {}
if type(item) is str:
return item
for key,struct in item.iteritems():
if type(struct) is str:
if key == 'I':
return int(struct)
else:
return struct
else:
for k,v in struct.iteritems():
if k == 'L':
value = []
for i in v:
value.append(parse_dynamo_item(i))
elif k == 'S':
value = str(v)
elif k == 'I':
value = int(v)
elif k == 'M':
value = {}
for a,b in v.iteritems():
value[a] = parse_dynamo_item(b)
else:
key = k
value = parse_dynamo_item(v)
resp[key] = value
return resp
@ademidun
Copy link

Thanks for this @JamieCressey, note if you are in python 3 use dict.items() instead of dict.iteritems()

https://stackoverflow.com/questions/30418481/error-dict-object-has-no-attribute-iteritems-when-trying-to-use-networkx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment