Jolt transform json-如何添加默认字段

时间:2019-06-18 18:39:49

标签: json transformation apache-nifi default-value jolt

我在下方输入JSON

{
  "id": "2ef8a2ee-054f-4b43-956a-8aa4f51a41d5",
  "type": "VOICE",
  "tags": [
    {
      "id": "some id 1",
      "description": "some description 1"
    },
    {
      "id": "some id 2",
      "description": "some description 2"
    }
  ],
  "transcription": {
    "key1": "val1",
    "key2": "val2"
  }
}

但是,输出JSON应该看起来类似,并且仅添加默认值:

{
  "id": "2ef8a2ee-054f-4b43-956a-8aa4f51a41d5",
  "created": "2019-06-18T18:12:37",
  "firstName": "Khusan",
  "lastName": "Sharipov",
  "status": "OPEN"
  "type": "VOICE",
  "tags": [
    {
      "id": "some id 1",
      "description": "some description 1"
    },
    {
      "id": "some id 2",
      "description": "some description 2"
    }
  ],
  "transcription": {
    "key1": "val1",
    "key2": "val2"
  }
}

这是我的JOLT规范:

[
  {
    "operation": "shift",
    "spec": {
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "": "TRASH",
        "*": {
          "$": "&2"
        }
      }
    }
  },
  {
    "operation": "remove",
    "spec": {
      "TRASH": ""
    }
  },
  {
    "operation": "default",
    "spec": {
      "firstName": "Khusan",
      "lastName": "Sharipov",
      "status": "OPEN"
    }
  }
]

我应该编辑JOLT规范,但我不知道如何操作(默认字段的名字,姓氏和状态有效。创建的字段可以添加为“创建的”:“ @(3,及时忍者) “

1 个答案:

答案 0 :(得分:3)

如果只想添加新字段,则只需要使用default操作,如下所示:

[
  {
    "operation": "default",
    "spec": {
      "firstName": "Khusan",
      "lastName": "Sharipov",
      "status": "OPEN"
    }
  }
]