code: def to_json(self):
      
      # Use the member variable (since we don't have access to the context) to
      # flush each pool to minimize the size of each filehandle before we
      # serialize it.
      for pool in self._pools:
        if pool is not None:
          pool.flush(True)
      return {"filehandles": pickle.dumps(self._filehandles)}
docs: Returns writer state to serialize in json.
  
      Returns:
        A json-izable version of the OutputWriter state.