Every line of 'python json check if key exists' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
133 def _check_key_exists(d: dict, key: object, custom_exception=None) -> None: 134 """ Check if a key exists inside a dictionary. Otherwise, raise KeyError or a custom exception. """ 135 try: 136 d[key] 137 except KeyError: 138 if custom_exception: 139 raise custom_exception 140 else: 141 raise KeyError
90 def check(json_data): 91 data = json.loads(json_data) 92 texts = data['ImageText'] 93 94 # no text at all 95 if len(texts) == 0: 96 logging.debug("No text") 97 return True 98 99 # very little text 100 if len(texts) == 1: 101 logging.debug("One text label") 102 return True 103 104 # all the text is within the border area (probably an artifact) 105 if all_in_border(data['ImageBB'], texts): 106 logging.debug("All text is in upper or lower border") 107 return True 108 109 # almost the whole image is text 110 # use crude implementation where we just sum up the text area 111 # and kick something out if >50% is text 112 a = area(data['ImageBB']) 113 if is_sum_larger(a*0.5, texts): 114 logging.debug("Almost everything is text") 115 return True 116 117 return False
38 def has_key(key, keys): 39 for k in keys: 40 if k['id'] == key: 41 return True 42 return False