def parse_json()

in scripts/error_code_generator_defs/error_code_defs_generator.py [0:0]


    def parse_json(self):
        """
        Parses the json file from the json_path passed at object creation and stores data

        Returns true on success; false on failure
        """
        try:
            file = open(self.json_path)

        except FileNotFoundError as e:
            print("Could not JSON file for reading at: " +
                  str(self.json_path) + " ", e)
            return False
        except Exception as e:
            print(
                f"An unknown error occurred while opening the json file path at: {self.json_path} ", e)
            return False

        try:
            result_json = json.load(file)

        except Exception as e:
            print(
                f"An unknown error occurred while loading the json from file path: {self.json_path}", e)
            return False

        facilities = result_json["facilities"]

        for facility_json_obj in facilities:

            f_code = facility_json_obj["code"]

            if (type(f_code) != int):
                print("Facility codes must be of type int")
                return False

            f_name = facility_json_obj["name"]

            if (type(f_name) != str):
                print("Facility names must be of type str")
                return False

            f_doc_string = facility_json_obj["doc_string"]

            if (type(f_doc_string) != str):
                print("Facility doc strings must be of type str")
                return False

            facility = FacilityCode(f_name, f_code, f_doc_string)

            if (not self.add_facility_code(facility)):
                print(f"Facility {f_name} is a duplicate!")
                return False

            for component_json_obj in facility_json_obj["components"]:

                c_code = component_json_obj["code"]

                if (type(c_code) != int):
                    print("Component codes must be of type int")
                    return False

                c_name = component_json_obj["name"]

                if (type(c_name) != str):
                    print("Component names must be of type str")
                    return False

                c_doc_string = component_json_obj["doc_string"]

                if (type(c_doc_string) != str):
                    print("Component doc strings must of type str")
                    return False

                component = ComponentCode(c_name, c_code, c_doc_string, f_code)

                if (not facility.add_component(component)):
                    print(f"Component {component.name} is a duplicate!")
                    return False

                for result_json_obj in component_json_obj["results"]:

                    r_val = result_json_obj["value"]

                    if (type(r_val) != int):
                        print("Result code must be of type int")
                        return False

                    r_name = result_json_obj["name"]

                    if (type(r_name) != str):
                        print("Result name must be of type str")
                        return False

                    result = ResultCode(r_name, r_val, f_code, c_code)

                    if (not component.add_result(result)):
                        print(f"Result code: {r_name} is a duplicate!")
                        return False

        return True