如何使用 NiFi 将字符串转换为 JSON 数组 [英] How to convert a string to a JSON array using NiFi
问题描述
在 NiFi 中,我正在处理一个包含以下属性的流文件:
In NiFi I'm processing a flowfile containing the following attribute:
Key: 'my_array'
Value: '[u'firstElement', u'secondElement']'
我想在这个数组上拆分 flowFile 以分别处理每个元素(然后合并).我尝试使用 SplitJson
处理器,但它需要操作 JSON 内容,所以我在它之前使用了 AttributesToJSON
.不幸的是,产生的 flowFile 的内容是:
I'd like to split flowFile on this array to process each element separately (and then merge). I tried to use SplitJson
processor, but it requires JSON content to operate on, so I used AttributesToJSON
before it. Unfortunately the produced flowFile's content is:
{"my_array": "[u'firstElement', u'secondElement'"}
我收到错误
$['my_array'] 的计算值 [u'firstElement', u'secondElement'] 不是 JSON 数组兼容类型,无法拆分.
The evaluated value [u'firstElement', u'secondElement'] of $['my_array'] was not a JSON Array compatible type and cannot be split.
是否可以将 my_array
字符串转换为正确的 JSON 数组?我需要使用 ExecuteScript
还是有一些更简单的方法?
Is it possible to convert my_array
string to the correct JSON array? Do I need to use ExecuteScript
or is there some simpler way?
推荐答案
ReplaceText
与 Always Replace
和 的
然后是 Replacement Strategy
怎么样${my_array}
的 >Replacement ValueSplitJSON
?这将使用此属性的值替换 FlowFile 的内容,然后您可以在其上 SplitJSON
.
How about ReplaceText
with Replacement Strategy
of Always Replace
and Replacement Value
of ${my_array}
and then SplitJSON
?
This will replace your FlowFile's content with this attribute's value and then you could SplitJSON
on it.
这篇关于如何使用 NiFi 将字符串转换为 JSON 数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!