【问题标题】:Update Json-Attributes in Apache-Nifi: Jolt在 Apache-Nifi 中更新 Json 属性:Jolt
【发布时间】:2017-09-21 08:59:21
【问题描述】:

我是 Apache Nifi 的新手,遇到以下问题:我想转换一个 json 文件,如下所示: 来自:

{
    "Property1": "x1",
    "Property2": "Tag_**2ABC**",
    "Property3": "x3",
    "Property4": "x4"
    }

到:

{
    "**2ABC**_Property1": "x1",
    "**2ABC**_Property3": "x3",
    "**2ABC**_Property4": "x4"
    },

它的意思是:从某个属性中获取值来更新所有其他属性。 我可以找到使用 JoltTransformer-Processor 的示例,当更新仅添加一个字符串时效果很好。但不适用于我的情况 到目前为止我所做的:我已经使用 evaluateJSONPath 处理器设置了每个属性。但是我只是尝试了很多可能性来使用更新属性处理器来完成它,但没有成功。我所有可能的测试看起来像(在 UpdateAttribute 内):

Property1 --> ${'Property2':substring(4,6)}"_"${'Property1'}

使用 Jolt:

[
{"operation": "modify-overwrite-beta",
    "spec": {
        "Property1": "${'Property2':substring(4,6)}_${'Property1'}"
            }
}
]

我在这里遗漏了哪一点?提前致谢!

【问题讨论】:

    标签: json apache-nifi jolt update-attribute


    【解决方案1】:

    我不了解 Nifi,但您可以在 Jolt 中做到这一点。

    规格

    [
      {
        "operation": "shift",
        "spec": {
          // match Property2
          "Property2": {
            "Tag_*": { // capture the nasty "**2ABC**" part to reference later
              // go back up the tree to the root
              "@2": {
                // match and ignore Property2
                "Property2": null,
                //
                // match Property* and use it and the captured 
                //  "prefix" to create the output key
                //  &(2,1) references the Tag_*, and pull off the "**2ABC**" part
                "Property*": "&(2,1)_&"
              }
            }
          }
        }
      }
    ]
    

    【讨论】:

    • 非常感谢!希望 OP 会接受:NiFi 接受所有 Jolt 规范,只需选择“Shift”然后粘贴 Milo 的规范 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多