【发布时间】:2019-06-26 08:45:00
【问题描述】:
在 NiFi 中,我正在处理包含以下属性的流文件:
Key: 'my_array'
Value: '[u'firstElement', u'secondElement']'
我想在这个数组上拆分 flowFile 以分别处理每个元素(然后合并)。我尝试使用SplitJson处理器,但它需要JSON内容才能操作,所以我在它之前使用了AttributesToJSON。不幸的是,产生的flowFile的内容是:
{"my_array": "[u'firstElement', u'secondElement'"}
我收到了错误
$['my_array'] 的计算值 [u'firstElement', u'secondElement'] 不是 JSON Array 兼容类型,无法拆分。
是否可以将 my_array 字符串转换为正确的 JSON 数组?我需要使用ExecuteScript 还是有更简单的方法?
【问题讨论】:
-
[u'firstElement', u'secondElement']的 json 格式无效。我认为这是一种 python 格式。 -
是的,这些值来自 Python,但我认为主要问题是使用
"[u'firstElement', u'secondElement']"而不是[u'firstElement', u'secondElement'] -
带双引号 - 它只是一个字符串。没有 - 不是有效的 json。你能从 python 生成 json 吗?
-
我尝试将其转换为Python中的列表,但它导致错误
org.python.core.PyList cannot be cast to java.lang.String,因此Python脚本似乎必须返回字符串。 -
使用
json.dumps(...)将python数据转换为json格式的字符串