【问题标题】:JOLT transformation for Nifi, flattening array and moving keysNifi 的 JOLT 转换,展平数组和移动键
【发布时间】:2020-09-16 20:26:18
【问题描述】:

我正在尝试扁平化 JSON 输出,同时将其中的一部分移动到较低的数组中。在下面的示例中,我需要将所有内容保留在“值”下,并将“时间戳”移动到值结果中。任何提示或文档可以提供帮助?

谢谢!

输入:

{   "readings": [
    {
      "meter": "78522546",
      "records": [
        {
          "timestamp": "22/02/2019 17:10:00",
          "values": {
            "DateTime": 1550848206,
            "ExportWh": 2136.5,
          }
        },
        {
          "timestamp": "22/02/2019 17:15:00",
          "values": {
            "DateTime": 1550848206,
            "ExportWh": 2136.5,
          }
        }
      ]
    },
    {
      "meter": "78522548",
      "records": [
        {
          "timestamp": "22/02/2019 17:15:00",
          "values": {
            "DateTime": 1550848246,
            "ExportWh": 0,
          }
        }
      ]
    },
    {
      "meter": "78522570",
      "records": [
        {
          "timestamp": "22/02/2019 17:10:00",
          "values": {
            "DateTime": 1550848226,
            "ExportWh": 3152012603293.037,
          }
        }
      ]
    },
    {
      "meter": "78522572",
      "records": [
        {
          "timestamp": "22/02/2019 17:10:00",
          "values": {
            "DateTime": 1550848236,
            "ExportWh": 1112.172,
          }
        }
      ]
    },
    {
      "meter": "78522589",
      "records": [
        {
          "timestamp": "22/02/2019 17:10:00",
          "values": {
            "DateTime": 1550848217,
            "ExportWh": 0,
          }
        }
      ]
    }   ] }

期望的输出:

{
    "timestamp": "22/02/2019 17:10:00",
    "DateTime": 1550848206,
    "ExportWh": 2136.5
},{
    "timestamp": "22/02/2019 17:15:00",
    "DateTime": 1550848206,
    "ExportWh": 2136.5
},{
    "timestamp": "22/02/2019 17:15:00",
    "DateTime": 1550848246,
    "ExportWh": 0
},{
    "timestamp": "22/02/2019 17:10:00",
    "DateTime": 1550848226,
    "ExportWh": 3152012603293.037
},{
    "timestamp": "22/02/2019 17:10:00",
    "DateTime": 1550848236,
    "ExportWh": 1112.172
},{
    "timestamp": "22/02/2019 17:10:00",
    "DateTime": 1550848217,
    "ExportWh": 0
}

这是我对规范的了解,但从这里开始继续循环:

[
  {
    "operation": "shift",
    "spec": {
      "readings": {
        "*": {
          "records": {
            "*": {
              "timestamp": "&",
              "@(0,values)": ""
            }
          }
        }
      }
    }
  }
]

【问题讨论】:

    标签: apache-nifi jolt


    【解决方案1】:

    检查此规范

    [
      {
        "operation": "shift",
        "spec": {
          "readings": {
            "*": {
              "records": {
                "*": {
                  "values": {
                    "@": "[].@(2,timestamp)"
                  }
                }
              }
            }
          }
        }
      }, {
        "operation": "shift",
        "spec": {
          "*": {
            "*": {
              "@": "[]",
              "$": "[&2].timestamp"
            }
          }
        }
      }
    ]
    

    【讨论】:

    • 就是这样!谢谢!我以为我很接近,但显然不是。
    猜你喜欢
    • 1970-01-01
    • 2021-09-13
    • 2022-11-24
    • 2021-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多