Apache Nifi 1.7.1 使用分隔符压平 Json

irr*_*ser 4 json jolt apache-nifi

我正在使用带有分隔符的 Flatten Json 处理器_,到目前为止,它可以很好地展平嵌套记录。但我也注意到它会干扰已经有“_”的键。例如:

{
"first_name": "myfirstname",
"last_name":  "mylastname",
"address": {
            "billing": "mybilling",
            "shipping": "myshipping"
           }
}
Run Code Online (Sandbox Code Playgroud)

展平为:

{
"[\"first_name\"]": "myfirstname",
"[\"last_name\"]":  "mylastname",
"address_billing": "mybilling",
"address_shipping": "myshipping"
 }
Run Code Online (Sandbox Code Playgroud)

同时,“ ”记录按预期被展平,具有字符address的键first_name和也受到干扰。有什么办法可以绕过这个吗?(也许是一种逃避非记录类型的方法?)last_name_

Shu*_*Shu 5

要解决此问题,您可以使用

  • JoltTransformJson处理器

    (或者)

  • 将分隔符(如“|”、“-”..等)保留在FlattenJson中,即 not present in key名称。

1.使用JoltTransformJson处理器:

规格:

[
  {
    "operation": "shift",
    "spec": {
      "*": "&",
      "address": {
        "*": "address_&"
      }
    }
  }
]
Run Code Online (Sandbox Code Playgroud)

输出:

{
  "first_name" : "myfirstname",
  "last_name" : "mylastname",
  "address_billing" : "mybilling",
  "address_shipping" : "myshipping"
}
Run Code Online (Sandbox Code Playgroud)

2.FlattenJson处理器:

在此输入图像描述

输出:

{
    "first_name": "myfirstname",
    "last_name": "mylastname",
    "address|billing": "mybilling",
    "address|shipping": "myshipping"
}
Run Code Online (Sandbox Code Playgroud)