Skip to content

Commit 7daee09

Browse files
authored
Remove items whose value is None before dumping to JSON (#53)
Some add-on submissions, such as this one are failing. The problem appears to be that optional values in the JSON metadata are being given a value of null, rather than omitted. Since null is a value, and the datatype for these keys is string, the validation fails. Thus, remove any None values from the add-on metadata before dumping to JSON. I believe this is safe, as we have already validated that all required keys are present, so any Nones on the dataclass are optional keys that haven't been provided.
1 parent 4aa1e8e commit 7daee09

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

_validate/createJson.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,18 @@ def generateJsonFile(
7272
filePath = buildOutputFilePath(data, parentDir)
7373

7474
with open(filePath, "wt", encoding="utf-8") as f:
75-
json.dump(dataclasses.asdict(data), f, indent="\t", ensure_ascii=False)
75+
json.dump(
76+
dataclasses.asdict(
77+
data,
78+
# The JSON schema does not permit null values, but does contain optional keys.
79+
# We have already ensured that all required keys are present in the metadata,
80+
# So we can safely delete all keys whose value is None as optional.
81+
dict_factory=lambda args: dict(filter(lambda item: item[1] is not None, args)),
82+
),
83+
f,
84+
indent="\t",
85+
ensure_ascii=False,
86+
)
7687
print(f"Wrote json file: {filePath}")
7788

7889

0 commit comments

Comments
 (0)