in aliyun/log/etl_core/trans_comp/trans_json.py [0:0]
def _expand_json(self, event, key, value, parent_list, parent_rlist, depth, sep, prefix, suffix):
# check if need to format it directly
if len(parent_list) > depth \
or (not isinstance(value, (list, tuple, dict))) \
or (isinstance(value, (list, tuple)) and not self.expand_array):
# 1. depth hit, 2. basic type, 3. array but not expand
logger.info(u"json_transformer: hit stop parsing, key: '{0}', value: '{1}', parent: '{2}', depth: '{3}'"
.format(key, value, parent_list, depth))
self.format_add_kv(event, self.fmt, self._n(key), self._n(value), parent_list, parent_rlist, sep, prefix,
suffix)
return None
# convert array to dict
if isinstance(value, (list, tuple)):
value = dict(
(self.format_array.format(parent_list=parent_list, parent_rlist=parent_rlist, index=i), v) for i, v in
enumerate(value))
if isinstance(value, dict):
for k, v in six.iteritems(value):
if isinstance(v, (dict, tuple, list)):
# recursively parse it
self._expand_json(event, k, v, parent_list + (k,), (k,) + parent_rlist, depth, sep, prefix, suffix)
else:
self.format_add_kv(event, self.fmt, self._n(k), self._n(v), parent_list, parent_rlist, sep, prefix,
suffix)
else:
logger.info(u"json_transformer: skip unsupported message '{0}' of type '{1}' when expanding"
.format(value, type(value)))