Support Questions

Find answers, ask questions, and share your expertise

How does NIFI handle JSON reorganization

avatar
New Contributor

未处理的表格:

{

    "日期":"2022-09-03 19:23:53",

    “设备名称”:“032-013”,

    "device_id":"1144",

    “传感器”:[

        {

            "sensor_id":"5836",

            “价值”:“1”,

            “传感器名称”:“设备状态

        },

        {

            "sensor_id":"5842",

            “价值”:””,

            “传感器名称”:“12345”

        }

 

        ],

    “状态”:“1”

}

最后结果: 

{

    “日期” “2022-09-03 19:23:53”

    “设备名称” “032-013”

    “device_id” “1144”

    “sensor_id” “5836”

    “价值” “1”

    “传感器名称” “设备状态”

    “状态” “1”

}

{

    “日期” “2022-09-03 19:23:53”

    “设备名称” “032-013”

    “device_id” “1144”

    “sensor_id” “58 42

    “价值” “1”

    “传感器名称” 12345

    “状态” “1”

}

 

我已经使用 splitjson 将传感器环出,Device_id 和 device_name 也可以通过 EvaluateJsonPath 获得。  

m_hsn_3-1646815557260.png

 

但是现在我不知道如何聚合来自两个处理器的数据?

 

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION

avatar
Super Guru

@m_hsn ,

 

You can use the JoltTransformJSON processor to flatten this JSON structure, using the following JOLT specification:

[
  {
    "operation": "shift",
    "spec": {
      "sensor": {
        "*": {
          "*": "[&1].&",
          "@(2,date)": "[&1].date",
          "@(2,device_name)": "[&1].device_name",
          "@(2,device_id)": "[&1].device_id",
          "@(2,status)": "[&1].status"
        }
      }
    }
  }
]

 

Cheers,

André

--
Was your question answered? Please take some time to click on "Accept as Solution" below this post.
If you find a reply useful, say thanks by clicking on the thumbs up button.

--
Was your question answered? Please take some time to click on "Accept as Solution" below this post.
If you find a reply useful, say thanks by clicking on the thumbs up button.

View solution in original post

2 REPLIES 2

avatar
Super Guru

@m_hsn ,

 

You can use the JoltTransformJSON processor to flatten this JSON structure, using the following JOLT specification:

[
  {
    "operation": "shift",
    "spec": {
      "sensor": {
        "*": {
          "*": "[&1].&",
          "@(2,date)": "[&1].date",
          "@(2,device_name)": "[&1].device_name",
          "@(2,device_id)": "[&1].device_id",
          "@(2,status)": "[&1].status"
        }
      }
    }
  }
]

 

Cheers,

André

--
Was your question answered? Please take some time to click on "Accept as Solution" below this post.
If you find a reply useful, say thanks by clicking on the thumbs up button.

--
Was your question answered? Please take some time to click on "Accept as Solution" below this post.
If you find a reply useful, say thanks by clicking on the thumbs up button.

avatar
New Contributor

thanks a lot