PyFunceble/helpers.py
def to_json(self, destination):
        """
        Save a dictionnary into a JSON file.

        :param destination:
            A path to a file where we're going to
            write the converted dict into a JSON format.
        :type destination: str
        """

        try:
            with open(destination, "w") as file:
                # We open the file we are going to write.
                # Note: We always overwrite the destination.

                # We save the current dictionnary into a json format.
                dump(
                    self.main_dictionnary,
                    file,
                    ensure_ascii=False,
                    indent=4,
                    sort_keys=True,
                )
        except UnicodeEncodeError:  # pragma: no cover
            with open(destination, "w", encoding="utf-8") as file:
                # We open the file we are going to write.
                # Note: We always overwrite the destination.

                # We save the current dictionnary into a json format.
                dump(
                    self.main_dictionnary,
                    file,
                    ensure_ascii=False,
                    indent=4,
                    sort_keys=True,
                )
def to_json(self, destination):
        try:
            with open(destination, "w") as file:
                # We open the file we are going to write.
                # Note: We always overwrite the destination.

                # We save the current dictionnary into a json format.
                dump(
                    self.main_dictionnary,
                    file,
                    ensure_ascii=False,
                    indent=4,
                    sort_keys=True,
                )
        except UnicodeEncodeError:  # pragma: no cover
            with open(destination, "w", encoding="utf-8") as file:
                # We open the file we are going to write.
                # Note: We always overwrite the destination.

                # We save the current dictionnary into a json format.
                dump(
                    self.main_dictionnary,
                    file,
                    ensure_ascii=False,
                    indent=4,
                    sort_keys=True,
                )
def to_json ( self , destination ) : try : with open ( destination , "w" ) as file : # We open the file we are going to write. # Note: We always overwrite the destination. # We save the current dictionnary into a json format. dump ( self . main_dictionnary , file , ensure_ascii = False , indent = 4 , sort_keys = True , ) except UnicodeEncodeError : # pragma: no cover with open ( destination , "w" , encoding = "utf-8" ) as file : # We open the file we are going to write. # Note: We always overwrite the destination. # We save the current dictionnary into a json format. dump ( self . main_dictionnary , file , ensure_ascii = False , indent = 4 , sort_keys = True , )
Save a dictionnary into a JSON file.

        :param destination:
            A path to a file where we're going to
            write the converted dict into a JSON format.
        :type destination: str
Save a dictionnary into a JSON file .