Fix _get_field not finding all fields

This commit is contained in:
Esa Kataja
2025-03-13 14:20:49 +02:00
parent a5e902a434
commit f93584a97d
+8 -3
View File
@@ -12,8 +12,13 @@ def _get_fields(json_data: dict) -> list[str]:
Returns: Returns:
list[str]: A list of field names extracted from the JSON data. list[str]: A list of field names extracted from the JSON data.
""" """
attributes = json_data["conceptCodes"][0]["attributes"] namelist = []
namelist = [attribute["attributeName"] for attribute in attributes] for attr in json_data["conceptCodes"]:
for name in attr["attributes"]:
if name["attributeName"] not in namelist:
namelist.append(name["attributeName"])
return namelist return namelist
def parse_json(json_file: Path) -> list[str]: def parse_json(json_file: Path) -> list[str]:
@@ -32,6 +37,6 @@ def parse_json(json_file: Path) -> list[str]:
try: try:
with open(json_file, "r") as f: with open(json_file, "r") as f:
json_data = json.load(f) json_data = json.load(f)
except json.JSONDecodeError as e: except json.JSONDecodeError:
raise click.FileError(json_file, "Not a valid JSON file.") raise click.FileError(json_file, "Not a valid JSON file.")
return _get_fields(json_data) return _get_fields(json_data)