def json2py(jsonstr):
 if (not isinstance(jsonstr, str)):
  return jsonstr
 from xml.sax.saxutils import unescape
 try:
  jsonstr = unescape(jsonstr, {"u'": '"'})
  jsonstr = unescape(jsonstr, {"'": '"'})
  python_structure = json.loads(jsonstr)
 except ValueError:
  _debug(('ERROR: attempting to convert %s using modules/s3db/survey/json2py.py' % jsonstr))
  return jsonstr
 else:
  return python_structure

def json2py ( jsonstr ) : if ( not isinstance ( jsonstr , str ) ) : return jsonstr from xml . sax . saxutils import unescape try : jsonstr = unescape ( jsonstr , { "u'" : '"' } ) jsonstr = unescape ( jsonstr , { "'" : '"' } ) python_structure = json . loads ( jsonstr ) except ValueError : _debug ( ( 'ERROR: attempting to convert %s using modules/s3db/survey/json2py.py' % jsonstr ) ) return jsonstr else : return python_structure
utility function to convert a string in json to a python structure .