我有Json数组,其每个对象都有动态属性。我必须将所有对象合并到nifi中的一个Json对象中

时间:2019-05-14 08:20:19

标签: apache-nifi jolt

我有Json数组,其每个对象都有动态属性。我必须将所有对象合并到nifi中的一个Json对象中,并连接普通属性值和其他属性。

我已经尝试按照规范进行操作,它提供了常用属性作为数组列表。但是,我希望将该公共属性的值连接在一起,但我不知道该怎么做。任何建议都会很有帮助。提前致谢。

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": "&"
      }
    }
    }
]

输入就像(注:属性是动态的,因此不确定总是要具有这些属性)

[
  {
    "firstName": "Sam1",
    "lastName": "Achom1",
    "place": "Silchar1"
  },
  {
    "firstName": "Saya2",
    "lastName": "Singh2",
    "place": "Macherial2",
    "Second1stAttribute": "SomeValue"
  },
  {
    "firstName": "Sam3",
    "lastName": "Achom3",
    "place": "Silchar3",
    "Third2ndAttribute": "SomeValue2"
  }
]

我在前面提到的规范中得到的输出

{
  "firstName" : [ "Sam1", "Saya2", "Sam3" ],
  "lastName" : [ "Achom1", "Singh2", "Achom3" ],
  "place" : [ "Silchar1", "Macherial2", "Silchar3" ],
  "Second1stAttribute" : "SomeValue",
  "Third2ndAttribute" : "SomeValue2"
}

并且期望输出为

{ "firstName" : "Sam1 Saya2 Sam3",
  "lastName" : "Achom1 Singh2 Achom3",
  "place" : "Silchar1 Mancherial2 Silchar3",
  "Second1stAttribute" : "SomeValue",
  "Third2ndAttribute" : "SomeValue2"
}

1 个答案:

答案 0 :(得分:0)

您可以“合并”阵列中的项目。该规范将达到目的:

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": "&"
      }
    }
    },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": "=join(' ',@(1,&))"
    }
    }
]