Skip to content

Instantly share code, notes, and snippets.

@bengrunfeld
bengrunfeld / make_ndb_return_data_json_serializable.py
Last active September 5, 2018 18:59
Convert NDB result to JSON Serializable data
def make_ndb_return_data_json_serializable(data):
"""Build a new dict so that the data can be JSON serializable"""
result = data.to_dict()
record = {}
# Populate the new dict with JSON serializiable values
for key in result.iterkeys():
if isinstance(result[key], datetime.datetime):
record[key] = result[key].isoformat()