def METHOD_NAME(self, file_name: Union[str, Path]) -> None:
    """Write the added packages to a file as JSON data.
    It ensures that the packages and every package's dependencies are sorted
    by the combination in the order of type, dev, name and version.
    :param file_name: an absolute or relative filename to write the added packages into.
        When a relative path is used, it will be opened directly and depends on the
        ``os.curdir``.
    :type file_name: str or pathlib.Path
    """
    self.sort()
    log.debug("Write packages with dependencies into file %s.", file_name)
    with open(file_name, "w", encoding="utf-8") as f:
        json.dump({"packages": self._packages}, f)