6

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)"

Michał Ziober
  • 37,175
  • 18
  • 99
  • 146
  • Your output `JSON` contains one more field: `created` with date. Your `JOLT` transformation does something with last name and first name which does not exist in input/output `JSON`. Could you please clarify what you would like to achieve? – Michał Ziober Jun 18 '19 at 18:56
  • yeah, output json has created, first name and last name fields. We can add these fields by default in jolt spec. I need output json like as input, but default field should be added in output json(((( sorry I cann't edit my spec as code :( – Khusan Sharipov Jun 18 '19 at 19:01
  • But could you edit your output `JSON` ans show how it should look like after transformation? – Michał Ziober Jun 18 '19 at 19:06
  • sure.. These three default fields I described in jolt spec. But I don't know how I can put sysdate for created field)) – Khusan Sharipov Jun 18 '19 at 19:13

1 Answers1

8

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"
    }
  }
]
Michał Ziober
  • 37,175
  • 18
  • 99
  • 146