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

Function json_encode

st2common/st2common/util/jsonify.py:103–118  ·  view source on GitHub ↗

Wrapper function for encoding the provided object. This function automatically select appropriate JSON library based on the configuration value. This function should be used everywhere in the code base where json.dumps() behavior is desired.

(obj, indent=None, sort_keys=False)

Source from the content-addressed store, hash-verified

101
102
103def json_encode(obj, indent=None, sort_keys=False):
104 """
105 Wrapper function for encoding the provided object.
106
107 This function automatically select appropriate JSON library based on the configuration value.
108
109 This function should be used everywhere in the code base where json.dumps() behavior is desired.
110 """
111 json_library = DEFAULT_JSON_LIBRARY
112
113 if json_library == "json":
114 return json_encode_native_json(obj=obj, indent=indent, sort_keys=sort_keys)
115 elif json_library == "orjson":
116 return json_encode_orjson(obj=obj, indent=indent, sort_keys=sort_keys)
117 else:
118 raise ValueError("Unsupported json_library: %s" % (json_library))
119
120
121def json_decode(data):

Callers 15

runMethod · 0.90
runMethod · 0.90
_json_body__setMethod · 0.90
__init__Method · 0.90
_json_body__setMethod · 0.90
connectMethod · 0.90
__call__Method · 0.90
__call__Method · 0.90
_fetch_and_compile_indexFunction · 0.90
fetch_pack_indexFunction · 0.90
_renderFunction · 0.90

Calls 2

json_encode_native_jsonFunction · 0.85
json_encode_orjsonFunction · 0.85