Fix _get_field not finding all fields
This commit is contained in:
+8
-3
@@ -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)
|
||||
Reference in New Issue
Block a user