如何将节点移动到数组中并键入 Nifi 中的给定节点?

How to move nodes into an array and key into the given node in Nifi?

我有 JSON 个这样的负载;

[
   {
      "Samples":{
         "Load":{
            "itemId":"bx",
            "timestamp":"2019-01-28T16:13:39.387640Z",
            "name":null
         },
         "Press":{
            "itemId":"by",
            "timestamp":"2019-01-28T16:13:39.387640Z",
            "name":null
         }
      }
   }
]

我想接收 JSON 如下所示:

{
   "Samples":{
      "Items":[
         {
            "tag_name":"Load",
            "itemId":"bx",
            "timestamp":"2019-01-28T16:13:39.387640Z",
            "name":null
         },
         {
            "tag_name":"Press",
            "itemId":"by",
            "timestamp":"2019-01-28T16:13:39.387640Z",
            "name":null
         }
      ]
   }
}

我该怎么做?我可以使用 JolTransformRecord 吗?这张唱片适合实时流媒体播放吗?

使用 GitHub 中非常相似的问题:Could you please assist me ? Moving nodes up into an array, and the key into the nodes 您可以找到解决方案。首先将整个对象复制到数组然后添加 tag_name:

的示例
[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "Samples": {
          "*": { // keys: Load or Press
            // Left hand side "@" means grab the whole object 
            //  that was the right hand side of Load or Press.
            // Then send it to Samples.Items array.
            "@": "Samples.Items[#2]",
            "$": "Samples.Items[#2].tag_name"
          }
        }
      }
    }
  }
]