我正在尝试将一行 XML 文件的全部内容插入到 JSON 属性中(我是新手)。

我是这样做的(告诉我是否有更简单的方法,现在很好):

我以这种方式配置了提取文本:

最后,我配置替换文本,提供 JSON 格式:

但他的结果似乎是错误的(不像普通的 JSON 文件那样工作,例如,如果我尝试做一个 httpPost):

我该如何解决这个问题?

干杯

请您参考如下方法:

如果您担心新行json 键/值,请使用NiFi expression language在提取的属性(data)上运行。

ReplaceText 配置:

重置值(value):

{"name" : "user1","time" : "${now()}","data" : "${data:replaceAll('\s',''):escapeJson()}"} 

使用escapeJsonreplaceAll函数将所有空格、换行替换为'' 替换策略为 Always Replace

(或)

另一种准备 json 消息的方法是使用 AttributesToJson 处理器。 如果我们正在使用此处理器,那么我们需要在使用 UpdateAttribute 处理器进行 AttributesToJson 处理器之前准备属性/值

:

1.SplitXml 
2.ExtractText //add data property to extract content to flowfile attribute 
3.UpdateAttribute //add name property -> user1  
                    add time property -> ${now()}  
                    add data property -> ${data:replaceAll('\s',''):escapeJson()}} 
4.AttributeToJson //Attributes List -> name,time,data 
                    Destination     -> flowfile content 
                    include core attributes -> false 


评论关闭
IT序号网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!