MCPcopy Create free account
hub / github.com/StackStorm/st2 / _get_value_simple

Function _get_value_simple

st2client/st2client/utils/jsutil.py:40–61  ·  view source on GitHub ↗

Extracts a value from a nested set of dictionaries 'doc' based on a 'key' string. The key string is expected to be of the format 'x.y.z' where each component in the string is a key in a dictionary separated by '.' to denote the next key is in a nested dictionary. Returns th

(doc, key)

Source from the content-addressed store, hash-verified

38
39
40def _get_value_simple(doc, key):
41 """
42 Extracts a value from a nested set of dictionaries 'doc' based on
43 a 'key' string.
44 The key string is expected to be of the format 'x.y.z'
45 where each component in the string is a key in a dictionary separated
46 by '.' to denote the next key is in a nested dictionary.
47
48 Returns the extracted value from the key specified (if found)
49 Returns None if the key can not be found
50 """
51 split_key = key.split(".")
52 if not split_key:
53 return None
54
55 value = doc
56 for k in split_key:
57 if isinstance(value, dict) and k in value:
58 value = value[k]
59 else:
60 return None
61 return value
62
63
64def _get_value_complex(doc, key):

Callers 1

get_valueFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected