def _json_convert(obj, json_options=DEFAULT_JSON_OPTIONS):
 if (hasattr(obj, 'iteritems') or hasattr(obj, 'items')):
  return SON(((k, _json_convert(v, json_options)) for (k, v) in iteritems(obj)))
 elif (hasattr(obj, '__iter__') and (not isinstance(obj, (text_type, bytes)))):
  return list((_json_convert(v, json_options) for v in obj))
 try:
  return default(obj, json_options)
 except TypeError:
  return obj

def _json_convert ( obj , json_options = DEFAULT_JSON_OPTIONS ) : if ( hasattr ( obj , 'iteritems' ) or hasattr ( obj , 'items' ) ) : return SON ( ( ( k , _json_convert ( v , json_options ) ) for ( k , v ) in iteritems ( obj ) ) ) elif ( hasattr ( obj , '__iter__' ) and ( not isinstance ( obj , ( text_type , bytes ) ) ) ) : return list ( ( _json_convert ( v , json_options ) for v in obj ) ) try : return default ( obj , json_options ) except TypeError : return obj
recursive helper method that converts bson types so they can be converted into json .