简体   繁体   English

通过 apache nifi 中的 jolt 处理器转换复杂数据

[英]Transform complex data by jolt processor in apache nifi

I have following expected input and expected output and i want to transform data by jolt processor我有以下预期的输入和预期的 output,我想通过 jolt 处理器转换数据

Input JSON输入 JSON

{
  "subscriptionId": "63",
  "data": [
    {
      "type": "demo",
      "Data": {
        "transactionId": "598958",
        "type": "json",
        "xyz": "pqr",
        "name": "john"
      },
      "nameData": [
        {
          "name": "Ama",
          "nameCount": "215",
          "genderData": [
            {
              "gender": "Male",
              "genderCount": "140"
            },
            {
              "gender": "Female",
              "genderCount": "75"
            }
          ]
        },
        {
          "name": "Aedes",
          "nameCount": "161",
          "genderData": [
            {
              "gender": "Female",
              "genderCount": "134"
            },
            {
              "gender": "Male",
              "genderCount": "27"
            }
          ]
        },
        {
          "name": "Culex",
          "nameCount": "2610",
          "genderData": [
            {
              "gender": "Male",
              "genderCount": "1926"
            },
            {
              "gender": "Female",
              "genderCount": "684"
            }
          ]
        },
        {
          "name": "Kamp",
          "nameCount": "465",
          "genderData": [
            {
              "gender": "Male",
              "genderCount": "465"
            }
          ]
        }
      ]
    }
  ]
}

Expected Output JSON预计 Output JSON

{
  "transactionId": "598958",
  "type": "json",
  "xyz": "pqr",
  "name": "john",
  "alert_array": [
    {
      "properties": [
        {
          "key": "Ama",
          "value": "215",
          "object": [
            {
              "key": "Male",
              "value": "140"
            },
            {
              "key": "Female",
              "value": "75"
            }
          ]
        },
        {
          "key": "Aedes",
          "value": "161",
          "object": [
            {
              "key": "Male",
              "value": "134"
            },
            {
              "key": "Female",
              "value": "27"
            }
          ]
        },
        {
          "key": "Culex",
          "value": "2610",
          "object": [
            {
              "key": "Male",
              "value": "1926"
            },
            {
              "key": "Female",
              "value": "684"
            }
          ]
        },
        {
          "key": "Kamp",
          "value": "465",
          "object": [
            {
              "key": "Male",
              "value": "465"
            }
          ]
        }
      ]
    }
  ]
}

I have the above following input JSON with nameData being an array and having genderData another array within it.我有上面的以下输入 JSON ,其中 nameData 是一个数组,而 genderData 是另一个数组。 Need to convert the input JSON to expected JSON output as shown above.需要将输入 JSON 转换为预期的 JSON output,如上图所示。 please suggest JOLT spec to transform the above JSON.请建议 JOLT 规范来转换上述 JSON。

You can start with determining the nodes alert_array , properties , object as diving to the innermost attributes within the shift transformation such as您可以从确定节点alert_arraypropertiesobject开始,以深入到 shift 转换中的最里面的属性,例如

[
  {
    "operation": "shift",
    "spec": {
      "data": {
        "*": {
          "Da*": "",
          "nameD*": {
            "*": {
              "name": "alert_array[0].properties[&1].key",
              "nameC*": "alert_array[0].properties[&1].value",
              "*": "alert_array[0].properties[&1].object"
            }
          }
        }
      }
    }
  },
  {
   // rename the innermost attributes
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "*": {
          "*": {
            "*": {
              "*": {
                "*": {
                  "key": "@(1,gender)",
                  "value": "@(1,genderCount)"
                }
              }
            }
          }
        }
      }
    }
  },
  {
   // get rid of the former names of the innermost attributes
    "operation": "remove",
    "spec": {
      "*": {
        "*": {
          "*": {
            "*": {
              "*": {
                "*": {
                  "gender": "",
                  "genderCount": ""
                }
              }
            }
          }
        }
      }
    }
  }
]

the demo on the site http://jolt-demo.appspot.com/ is http://jolt-demo.appspot.com/网站上的演示是

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM