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 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() |
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
#!/usr/bin/env python | |
""" | |
JSON encoder/decoder adapted for use with Google App Engine NDB. | |
Usage: | |
import ndb_json | |
# Serialize an ndb.Query into an array of JSON objects. | |
query = models.MyModel.query() |