def safe_dict(d):
 if isinstance(d, dict):
  return dict([(k.encode('utf-8'), safe_dict(v)) for (k, v) in d.items()])
 elif isinstance(d, list):
  return [safe_dict(x) for x in d]
 else:
  return d

def safe_dict ( d ) : if isinstance ( d , dict ) : return dict ( [ ( k . encode ( 'utf-8' ) , safe_dict ( v ) ) for ( k , v ) in d . items ( ) ] ) elif isinstance ( d , list ) : return [ safe_dict ( x ) for x in d ] else : return d
recursively clone json structure with utf-8 dictionary keys URL .