将对应于数组的空值转换为nifi jolt中的空数组

convert null values corresponding to an Array to empty array in nifi jolt

我想在 NIFI 中使用 Jolt 处理器实现以下 JSON 转换 通过关注值字段,在 json (id 900551) 的第一个输入中,值填充如下

输入JSON

{
    "id": 900551,
    "internal_name": [],
    "values": [
        {
            "id": 1430156,
            "form_field_id": 900551,
            "pos": 0,
            "weight": null,
            "category": null,
            "created_at": "2020-10-15 12:55:02",
            "updated_at": "2020-11-27 10:45:09",
            "deleted_at": null,
            "settings": {
                "image": "myimage.png"
                "fix": false,
                "bold": false,
                "exclusive": false
            },
            "internal_value": "494699DV7271000,6343060SX0W1000,619740BWR0W1000",
            "css_class": null,
            "value": "DIFFERENCE",
            "settings_lang": {},
            "value_html": ""
        }
    ]
}

在要解析的第二个输入 Json 文件中,值为空。

{
    "id": 900552,
    "internal_name": [],
    "values": []
}

我想在我的转换中将空值转换为空数组

有没有办法使用现有的 Jolt 操作来做到这一点?

谢谢。

default operation就是您要找的:

Defaultr walks the spec and asks "Does this exist in the data? If not, add it."

在我们的案例中:

if the value for "values" key is null, put the empty array instead

这是规范:

[
  {
    "operation": "default",
    "spec": {
      "values": []
    }
  }
]

测试 https://jolt-demo.appspot.com/


编辑: 回答评论中的问题:

也许 适合你