def convert_json_facts_to_dict(fact_list): fact_dict = {} for fact in fact_list: if "namespace" in fact and "facts" in fact: if fact["namespace"] in fact_dict: fact_dict[fact["namespace"]].update(fact["facts"]) else: fact_dict[fact["namespace"]] = fact["facts"] else: # The facts from the request are formatted incorrectly raise InputFormatException("Invalid format of Fact object. Fact " "must contain 'namespace' and 'facts' keys.") return fact_dict
def _deserialize_facts(data): facts = {} for fact in [] if data is None else data: try: if fact["namespace"] in facts: facts[fact["namespace"]].update(fact["facts"]) else: facts[fact["namespace"]] = fact["facts"] except KeyError: # The facts from the request are formatted incorrectly raise InputFormatException( "Invalid format of Fact object. Fact must contain 'namespace' and 'facts' keys." ) return facts