<s> try : <EOL> import simplejson as json <EOL> except ImportError : <EOL> import json <EOL> from pecan . jsonify import GenericJSON <EOL> import six <EOL> __all__ = [ <EOL> '<STR_LIT>' <EOL> ] <EOL> def json_encode ( obj , indent = <NUM_LIT:4> ) : <EOL> return json . dumps ( obj , cls = GenericJSON , indent = indent ) <EOL> def load_file ( path ) : <EOL> with open ( path , '<STR_LIT:r>' ) as fd : <EOL> return json . load ( fd ) <EOL> def json_loads ( obj , keys = None ) : <EOL> """<STR_LIT>""" <EOL> if not obj : <EOL> return None <EOL> if not keys : <EOL> keys = obj . keys ( ) <EOL> for key in keys : <EOL> try : <EOL> obj [ key ] = json . loads ( obj [ key ] ) <EOL> except : <EOL> pass <EOL> return obj <EOL> def try_loads ( s ) : <EOL> try : <EOL> return json . loads ( s ) if s and isinstance ( s , six . string_types ) else s <EOL> except : <EOL> return s </s>
