Open MagnusLii opened 7 months ago
def validateKeywordsInJSON(decodedJSON, keywordList, verifycationLevel):
jsonKeySet = set(decodedJSON.keys())
if verifycationLevel == 1:
for keyword in keywordList:
if keyword not in jsonKeySet:
return False
return True
elif verifycationLevel == 2:
for keyword in keywordList:
if keyword not in jsonKeySet or not decodedJSON[keyword] or decodedJSON[keyword] == "NULL":
return False
return True
else:
raise ValueError("Invalid verification level. Please provide either 1 or 2.")
Keyword Validation Function
Goal
The goal is to create a function that takes in a JSON object, a list of keywords, and a verification level. The function first checks the verification level and based on the level either verifies that all keywords are present or that all keywords are present and have a non empty or NULL value assigned to them.
Arguments
1
for validating the existence of keys.2
for validating both keys and their associated non-empty or NULL values.Returns
Boolean:
True
if the provided criteria are met;False
otherwise.Name of function
validateKeywordsInJSON