code: def write_file(self, content, filepath=None, filename=None, indent=None, keys_to_write=None):
          '''
          Write a Python dictionary as JSON to a file.
          :param content: Dictionary of key-value pairs to save to a file
          :param filepath: Path where the file is to be created
          :param filename: Name of the file to be created
          :param indent: You can use this to specify indent level for pretty printing the file
          :param keys_to_write: array of keys that are to be picked from data and written to file.
                  Default is None, when all data is written to file.
          :return: Path of file used
          :raises OSError, EnvironmentError, ValueError
          '''
          path = filepath if filepath else self.filepath
          name = filename if filename else self.filename
          if not os.path.exists(path):
              try:
                  os.makedirs(path)
              except OSError as error:
                  self.logger.error("Error while creating directory: {}".format(error))
                  raise
          name = self._ends_with(name, ".json")
          path = self._ends_with(path, os.path.sep)
          if keys_to_write:
              data_to_write = {}
              for key in keys_to_write:
                  data_to_write[key] = content[key]
          else:
              data_to_write = content
          try:
              indent = indent if indent else 2
              self._write_json(path, name, 'w', data_to_write, indent)
              return os.path.join(path, name)
          except EnvironmentError as error:
              self.logger.error("Error while opening or writing to file: {}".format(error))
              raise
          except ValueError:
              raise