class JSONEncoder(json.JSONEncoder):

    def default(self, o):
        if isinstance(o, db.Key):
            o = db.get(o)
if isinstance(o, db.Model):
    return db.to_dict(o)
elif isinstance(o, (datetime, date, time)):
    return str(o)
AppEngine Making ndb models json serializable