Khusan Sharipov
Khusan Sharipov

Reputation: 75

Jolt transform json - how to add default fields

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

Upvotes: 6

Views: 9452

Answers (1)

Michał Ziober
Michał Ziober

Reputation: 38655

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

Upvotes: 8

Related Questions