parameters: (json_obj)
return_statement: return _fix_json(json_obj)
docstring: Handle binary data in input json, because pymongo cannot decode them properly (leaving $binary as string)
docstring_summary: Handle binary data in input json, because pymongo cannot decode them properly (leaving $binary as string)
docstring_tokens: Handle binary data in input json because pymongo cannot decode them properly ( leaving $binary as string )
function: def fix_json_input(json_obj):
      """
          Handle binary data in input json, because pymongo cannot decode them properly (leaving $binary as string)
      """
      def _fix_json(d):
          if d in [None, [], {}]: #if not d: breaks empty Binary
              return d
          data_type = type(d)
          if data_type == list:
              data = []
              for item in d:
                  data.append(_fix_json(item))
              return data
          elif data_type == dict:
              data = {}
              if '$binary' in d: #base64 encoded data
                  return pymongo.binary.Binary(base64.decodestring(d['$binary']), d['$type'])
              else:
                  for k in d:
                      data[_fix_json(k)] = _fix_json(d[k])
              return data
          else:
              return d
  
      return _fix_json(json_obj)
function_tokens: def fix_json_input ( json_obj ) : def _fix_json ( d ) : if d in [ None , [ ] , { } ] : #if not d: breaks empty Binary return d data_type = type ( d ) if data_type == list : data = [ ] for item in d : data . append ( _fix_json ( item ) ) return data elif data_type == dict : data = { } if '$binary' in d : #base64 encoded data return pymongo . binary . Binary ( base64 . decodestring ( d [ '$binary' ] ) , d [ '$type' ] ) else : for k in d : data [ _fix_json ( k ) ] = _fix_json ( d [ k ] ) return data else : return d return _fix_json ( json_obj )