如何使用NiFi将字符串转换为JSON数组 [英] How to convert a string to a JSON array using NiFi

查看:451
本文介绍了如何使用NiFi将字符串转换为JSON数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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?

推荐答案

使用 Always Replace Replacement Strategy ReplaceText 怎么样?> $ {my_array} 的替换值,然后是 SplitJSON ?这将用此属性的值替换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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆