如果对象的一个字段为空,我如何使用NIFI中的JoltTransformJson处理器转换(在本例中为删除)流文件

下面是我的数据.

_

[
  {
    "Name" : "john Smith",
    "DOB" : "2000-07-14",
    "Salary" : 16000.0
  },
  {
    "Name" : "Sara Jacob",
    "DOB" : "2000-07-14",
    "Salary" : 12000.0
  },
  {
    "Name" : "Peter John",
    "DOB" : null,
    "Salary" : 20000.0
  },
  {
    "Name" : "Lia Poul",
    "DOB" : "2000-07-14",
    "Salary" : 18000.0
  }
]

我使用100处理器将JSON文件拆分成多个独立的FlowFiles,并将下游连接到101处理器.接下来,我将JoltTransformJson配置如下: 抖动变换DSL:链 Jolt规格:

[
  {
    "operation": "remove",
    "spec": {
      "rowsToRemove": {
        "*": {
          "DOB": {
            "$null": ""
          }
        }
      }
    }
  }
]

但是这个表达式只删除了道布字段,而不是整个对象和流文件.

推荐答案

是的,您可以使用100处理器和以下转换规格,其中包含主要解决问题的102函数,例如

[
  { // produce a new attribute, namely "Nl" to check whether the DOB is null
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "Nl": ["=notNull(@(1,DOB))", "NuLl"]
      }
    }
  },
  { // the following conditional spontaneously removes the object having "Nl" : "NuLl" pair
    "operation": "shift",
    "spec": {
      "*": {
        "Nl": {
          "NuLl": {
            "@2": "@3,Nl"
          },
          "*": {
            "@2": ""
          }
        }
      }
    }
  },
  { // get rid of the remaining "Nl" attributes
    "operation": "remove",
    "spec": {
      "*": {
        "Nl": ""
      }
    }
  }
]

站点http://jolt-demo.appspot.com/上的101

enter image description here

Json相关问答推荐

与错误相关的未定义&Quot;不是有效的JSON

组合不同属性的Jolt Spec

使用Kotlin限制序列化类属性的允许整数值

将 REST API - json 输出转换为表 Power BI

根据值过滤输入的JSON并使用它准备预期的输出

Oracle json 对象的最后一个值不在引号中

父键中的 Perl JSON 数组

我需要在 mongodb compass 中检索索引(编号 1)信息

派生类的属性没有得到价值

如何用 Xidel 正确读取这个 JSON 文件?

使用 Javascript 判断 JSON 对象是否包含值

为什么在测试 RSPEC 时 JBuilder 不返回 JSON 中的响应正文

如何在 jQuery 中循环遍历 JSON 数组?

应该使用什么标头将 GZIP 压缩 JSON 从 Android 客户端发送到服务器?

如何使用 C# 将 JSON 文本转换为对象

JSON 语法错误:'unexpected number' 或 'JSON.parse: expected ',' or '}' after property value in object'

JSON 到 JSON 转换器

如何使用 Jackson 注释从 HttpResponse 反序列化 JSON 对象?

类型是接口或抽象类,不能实例化

是否有一个 PHP 函数只在双引号而不是单引号中添加斜杠