Jolt transform json - how to add default fields

给你一囗甜甜゛ 提交于 2019-12-24 10:03:54

问题


I have below input 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"
  }
}

But, output JSON should look like similarly, and add only default values:

{
  "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"
  }
}

This is my JOLT spec:

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

I should edit JOLT spec but I do not understand how ( default fields first name, last name and status work. created can be added as "created": "@(3,ninjaed-in-time)"


回答1:


If you want to add only new fields you need to use only default operation like below:

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


来源:https://stackoverflow.com/questions/56655174/jolt-transform-json-how-to-add-default-fields

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!