Harsh Sharma
Harsh Sharma

Reputation: 31

Apache Nifi transform with JoltTranform processor

I have some attributes myId, count. Now with these attributes I want write down the Jolt format to get the following output.

{
  "projectId": "projectId",
  "ticketId": "NO_TICKET",
  "trigger": "SCHEDULED_BACKLOG",
  "timestamp": 1539060316494,
  "pivotVersion": 1,
  "pivotType": "FlattenedTodoStats",
  "todoCount": "todoCount",
  "pivots": [
    {
      "state": "BACKLOG",
      "type": "NA"
    }
  ]
}

Upvotes: 0

Views: 545

Answers (1)

notNull
notNull

Reputation: 31470

You can either use Jolt Transform (or) ReplaceText processors for this case.

As you are having some attributes to the flowfile so use ReplaceText processor enter image description here

In ReplaceMent Value configure as

{
    "projectId": "${projectId}",
    "ticketId": "${ticketId}",
    "trigger": "${trigger}",
    "timestamp": "${timestamp}",
    "pivotVersion":"${pivotVersion}",
    "pivotType":"${pivotType}",
    "todoCount":"${todoCount}",
    "pivots[]": {
      "*": {
        "state": "${state}",
        "type": "${type}"
      }
    }
}

Substitute all the attribute names(${projectId}..etc) with your attribute names.

Use Replacement Strategy as AlwaysReplace

(or)

If you want to use Jolt for this case then

Use default operation to replace your attribute values and prepare json message

Example:

enter image description here Jolt Specification

[{ "operation": "shift", "spec": { "z":"z" } }, { "operation": "default", "spec": { "projectId": "${projectId}", "ticketId": "${ticketId}", "trigger": "${trigger}", "timestamp": "${timestamp}", "pivotVersion":"${pivotVersion}", "pivotType":"${pivotType}", "todoCount":"${todoCount}", "pivots[]": { "*": { "state": "${state}", "type": "${type}" } } } }]

As i don't have any attribute values, so my output json is having all empty values in it.

Change the spec jolt spec as per your requirements.

Upvotes: 1

Related Questions