src/pds_doi_service/core/input/input_util.py
def parse_json_file(self, json_path):
        """
        Parses DOI's from a file with a .json extension. The file is expected
        to conform to the JSON schema associated to the service provider in use.

        Parameters
        ----------
        json_path : str
            Path to the JSON file to parse.

        Returns
        -------
        dois : List of Doi
            DOI objects parsed from the provided JSON file.

        """
        logger.info("Parsing json file %s", basename(json_path))

        dois = []
        web_parser = DOIServiceFactory.get_web_parser_service()
        validator = DOIServiceFactory.get_validator_service()

        # First read the contents of the file
        with open(json_path, "r") as infile:
            # It's been observed that input files transferred from Windows-based
            # machines can append a UTF-8-BOM hex sequence, which breaks
            # JSON parsing later on. So we perform an encode-decode here to
            # ensure this sequence is stripped before continuing.
            json_contents = infile.read().encode().decode("utf-8-sig")

        # Validate and parse the provide JSON label based on the service provider
        # configured within the INI. If there's a mismatch, the validation step
        # should catch it.
        try:
            if DOIServiceFactory.get_service_type() == SERVICE_TYPE_DATACITE:
                validator.validate(json_contents)

            dois, _ = web_parser.parse_dois_from_label(json_contents, content_type=CONTENT_TYPE_JSON)
        except InputFormatException as err:
            msg = f'Unable to parse DOI objects from provided json file "{json_path}"\nReason: {str(err)}'
            logger.warning(msg)
            raise InputFormatException(msg)

        return dois

        Parses DOI's from a file with a .json extension. The file is expected
        to conform to the JSON schema associated to the service provider in use.

        Parameters
        ----------
        json_path : str
            Path to the JSON file to parse.

        Returns
        -------
        dois : List of Doi
            DOI objects parsed from the provided JSON file.

        
Parses DOI's from a file with a .json extension. The file is expected
to conform to the JSON schema associated to the service provider in use.

Parameters

json_path : str
Path to the JSON file to parse.

Returns

dois : List of Doi
DOI objects parsed from the provided JSON file.
Parses DOI ' s from a file with a . json extension . The file is expected to conform to the JSON schema associated to the service provider in use . Parameters json_path : str Path to the JSON file to parse . Returns dois : List of Doi DOI objects parsed from the provided JSON file .
def parse_json_file(self, json_path):
        logger.info("Parsing json file %s", basename(json_path))
        dois = []
        web_parser = DOIServiceFactory.get_web_parser_service()
        validator = DOIServiceFactory.get_validator_service()
        with open(json_path, "r") as infile:
            json_contents = infile.read().encode().decode("utf-8-sig")
        try:
            if DOIServiceFactory.get_service_type() == SERVICE_TYPE_DATACITE:
                validator.validate(json_contents)
            dois, _ = web_parser.parse_dois_from_label(json_contents, content_type=CONTENT_TYPE_JSON)
        except InputFormatException as err:
            msg = f'Unable to parse DOI objects from provided json file "{json_path}"\nReason: {str(err)}'
            logger.warning(msg)
            raise InputFormatException(msg)
        return dois
def parse_json_file ( self , json_path ) : logger . info ( "Parsing json file %s" , basename ( json_path ) ) dois = [ ] web_parser = DOIServiceFactory . get_web_parser_service ( ) validator = DOIServiceFactory . get_validator_service ( ) with open ( json_path , "r" ) as infile : json_contents = infile . read ( ) . encode ( ) . decode ( "utf-8-sig" ) try : if DOIServiceFactory . get_service_type ( ) == SERVICE_TYPE_DATACITE : validator . validate ( json_contents ) dois , _ = web_parser . parse_dois_from_label ( json_contents , content_type = CONTENT_TYPE_JSON ) except InputFormatException as err : msg = f'Unable to parse DOI objects from provided json file "{json_path}"\nReason: {str(err)}' logger . warning ( msg ) raise InputFormatException ( msg ) return dois
Parses DOI's from a file with a .json extension.
Parses DOI ' s from a file with a . json extension .
"""
        Parses DOI's from a file with a .json extension. The file is expected
        to conform to the JSON schema associated to the service provider in use.

        Parameters
        ----------
        json_path : str
            Path to the JSON file to parse.

        Returns
        -------
        dois : List of Doi
            DOI objects parsed from the provided JSON file.

        """ # First read the contents of the file # It's been observed that input files transferred from Windows-based # machines can append a UTF-8-BOM hex sequence, which breaks # JSON parsing later on. So we perform an encode-decode here to # ensure this sequence is stripped before continuing. # Validate and parse the provide JSON label based on the service provider # configured within the INI. If there's a mismatch, the validation step # should catch it.
self
json_path