gpt4 book ai didi

apache-nifi - Nifi - 如何将 XML 整个内容插入 JSON 属性

转载 作者:行者123 更新时间:2023-12-02 08:04:40 27 4
gpt4 key购买 nike

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

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

enter image description here

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

enter image description here

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

enter image description here

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

enter image description here

我该如何解决这个问题?

干杯

最佳答案

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

ReplaceText 配置:

enter image description here重置值(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

关于apache-nifi - Nifi - 如何将 XML 整个内容插入 JSON 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52807154/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com