user4540719
user4540719

Reputation: 43

json formation in nifi using jolt transformjson

I am new to nifi. I need help to make new json template using jolttransform processor. could anyone please help to make joltspec for this requirement.

From convertavrotojson processor flow file am getting the following attributes

name, address, id,status

And from its content file, am getting mobileno.

Expecting the following output { "id": "1", "details":[ { "mobileno": "xxxxx", "name ": "AAAA", "address": "addressline1" } ], "status" :"true" }

Upvotes: 1

Views: 3681

Answers (1)

notNull
notNull

Reputation: 31470

As you are having name, address, id,status attributes to the flowfile,In new versions of NiFi-1.2+ we can add attributes into json message using jolt.

Try with below jolt spec:-

[
  {
    "operation": "shift",
    "spec": {
      "mobileno": "details[0].mobileno"
    }
  },
 {
        "operation": "default",
        "spec": {
          "id":"${id}",
          "status":"${status}",
            "details[]": {
                "*": {
                  "name":"${name}",
                  "address":"${address}"
                }
            }
        }
    }
]

Jolt Config screenshot:- enter image description here

For more reference

https://community.hortonworks.com/questions/152046/nifi-how-to-use-jolt-to-add-json-keyvalue-dynamica.html

Upvotes: 1

Related Questions