Neeraj
Neeraj

Reputation: 49

How to add new key in json flow by nifi jolt processor

how to convert the following data

{
  "name" : "abcd",
  "middleName" : "srivastav"
}

into

{
  "name" : "abcd",
  "middleName" : "srivastav"
  "id" : "abcd"
}

by using a jolt transform such that the id and the name are within the same object as the expected output.

Upvotes: 0

Views: 411

Answers (2)

Arnold Joseph
Arnold Joseph

Reputation: 545

modify-default-beta or default operations will work for this :

[
  {
    "operation": "modify-default-beta",
    "spec": {
      "id": "abcd"
    }
  }
]

Upvotes: 1

Barbaros Özhan
Barbaros Özhan

Reputation: 65408

One option is to replicate the value of name through use of "@(0,name)": while keeping the current attributes by "*": "&" notation within a shift transformation such as

[
  {
    "operation": "shift",
    "spec": {
      "*": "&",
      "@(0,name)": "id"
    }
  }
]

the demo on the site http://jolt-demo.appspot.com/ is enter image description here

or another option is to use a modify(overwrite/default) transformation to dynamically replicate the value of name attribute for id such as

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "id": "@(1,name)"
    }
  }
]

the second demo is

enter image description here

Upvotes: 0

Related Questions