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

Function _cast_object

st2common/st2common/util/casts.py:28–42  ·  view source on GitHub ↗

Method for casting string to an object (dict) or array. Note: String can be either serialized as JSON or a raw Python output.

(x)

Source from the content-addressed store, hash-verified

26
27
28def _cast_object(x):
29 """
30 Method for casting string to an object (dict) or array.
31
32 Note: String can be either serialized as JSON or a raw Python output.
33 """
34 x = _cast_none(x)
35
36 if isinstance(x, six.string_types):
37 try:
38 return json_decode(x)
39 except:
40 return ast.literal_eval(x)
41 else:
42 return x
43
44
45def _cast_boolean(x):

Callers

nothing calls this directly

Calls 2

json_decodeFunction · 0.90
_cast_noneFunction · 0.85

Tested by

no test coverage detected