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

Apache nifi Nifi-如何将XML整个内容插入JSON属性,apache-nifi,Apache Nifi,我试图将XML文件行的全部内容插入JSON属性(我是新手) 我是这样做的(如果有更简单的方法,请告诉我,最好现在就开始): 我以这种方式配置了提取文本: 最后,我配置Replace文本,给出JSON格式: 但他的结果似乎是错误的(不像正常的JSON文件那样工作,例如,如果我尝试执行httpPost): 我如何解决这个问题 干杯如果您关心新行和json键/值,请使用提取属性上的函数(数据) ReplaceText配置: {"name" : "user1","time" : "${now()

我试图将XML文件行的全部内容插入JSON属性(我是新手)

我是这样做的(如果有更简单的方法,请告诉我,最好现在就开始):

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

最后,我配置Replace文本,给出JSON格式:

但他的结果似乎是错误的(不像正常的JSON文件那样工作,例如,如果我尝试执行httpPost):

我如何解决这个问题


干杯

如果您关心
新行
json键/值
,请使用提取属性上的函数(
数据

ReplaceText配置:

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

{"name" : "user1","time" : "${now()}","data" : "${data:replaceAll('\s',''):escapeJson()}"}
使用escapeJsonreplaceAll函数将所有空格、换行符替换为
'
替换策略为“始终替换”

(或)

另一种准备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

谢谢我认为第二个选项将是更智能的解决方案:)结果更好,但现在在xml部分出现了很多“/”。我怎样才能解决这个问题1..@jmarco10,使用unescapeJson()删除xml部分中所有额外的“\”,如果这些额外的“\”是随机出现的,则使用ifElse语句并检查属性值是否包含“\”,然后应用unescapeJson()或应用escapeJson()函数。(或)如果这不起作用,请使用ReplaceText processor并搜索“\”文本并替换为空字符串。