<s> from datetime import date <EOL> import json <EOL> from sqlalchemy . ext . declarative import DeclarativeMeta <EOL> class MyJSONEncoder ( json . JSONEncoder ) : <EOL> def default ( self , obj , ** kwargs ) : <EOL> if isinstance ( obj . __class__ , DeclarativeMeta ) : <EOL> fields = { } <EOL> for field in [ x for x in dir ( obj ) if not x . startswith ( '<STR_LIT:_>' ) and x != '<STR_LIT>' ] : <EOL> data = obj . __getattribute__ ( field ) <EOL> try : <EOL> json . dumps ( data ) <EOL> fields [ field ] = data <EOL> except TypeError : <EOL> fields [ field ] = None <EOL> return fields <EOL> elif isinstance ( obj , date ) : <EOL> return obj . isoformat ( ) <EOL> return json . JSONEncoder . default ( self , obj , ** kwargs ) <EOL> def jsonify ( s ) : <EOL> return json . dumps ( s , indent = <NUM_LIT:2> , encoding = '<STR_LIT:utf-8>' , cls = MyJSONEncoder ) </s>
