代码之家  ›  专栏  ›  技术社区  ›  MDS

在Apache Nifi中更新Json属性:Jolt

  •  1
  • MDS  · 技术社区  · 7 年前

    我是Apache Nifi的新手,有以下问题:我想按如下方式转换json文件: 发件人:

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

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

    这意味着:从某个属性中获取值以更新所有其他属性。 到目前为止,我所做的是:我使用evaluateJSONPath处理器设置了每个属性。但我只是尝试了很多使用更新属性处理器的可能性,但没有成功。我所有可能的测试看起来像(在UpdateAttribute中):

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

    使用震动:

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

    1 回复  |  直到 7 年前
        1
  •  3
  •   Milo S    7 年前

    我不知道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)_&"
              }
            }
          }
        }
      }
    ]