diff --git a/src/json_parser.py b/src/json_parser.py index eec02be..f0f9c8b 100644 --- a/src/json_parser.py +++ b/src/json_parser.py @@ -12,8 +12,13 @@ def _get_fields(json_data: dict) -> list[str]: Returns: list[str]: A list of field names extracted from the JSON data. """ - attributes = json_data["conceptCodes"][0]["attributes"] - namelist = [attribute["attributeName"] for attribute in attributes] + namelist = [] + for attr in json_data["conceptCodes"]: + for name in attr["attributes"]: + if name["attributeName"] not in namelist: + namelist.append(name["attributeName"]) + + return namelist def parse_json(json_file: Path) -> list[str]: @@ -32,6 +37,6 @@ def parse_json(json_file: Path) -> list[str]: try: with open(json_file, "r") as f: json_data = json.load(f) - except json.JSONDecodeError as e: + except json.JSONDecodeError: raise click.FileError(json_file, "Not a valid JSON file.") return _get_fields(json_data) \ No newline at end of file