Skip to content

Instantly share code, notes, and snippets.

View alpocr's full-sized avatar

Allan Porras alpocr

View GitHub Profile
@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()
@erichiggins
erichiggins / ndb_json.py
Last active May 23, 2021 00:27
JSON serializer/deserializer adapted for use with Google App Engine's NDB Datastore API. This script can handle Model, Expando, PolyModel, Query, QueryIterator, Key, datetime, struct_time, and complex types.
#!/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()