Support Questions

Find answers, ask questions, and share your expertise

getting null from JoltTransformJson in nifi while converting a plain json to nested json

avatar
New Contributor

Hi,

I am using JoltTransformJson to convert a plain json to nested json in Nifi and getting null in the output. The same i/p and spec is working in Jolt demo. Below are the input and the spec 
Input:

{
"ts" : "2024-09-22T12:03:13.000Z",
"sourceDeviceId" : 4321,
"sourceName" : "light1",
"sourceType" : "light",
"locationLat" : 201.34,
"locationLon" : 101.5,
"locationId" : 1,
"recordDate" : "2024-09-22T12:03:13.000Z",
"_class" : "com.prutech.smartcity.entity.LightEntity",
"_id" : "66f27c487bd8652abecdb9c7",
"status" : "INACTIVE",
"power" : 0,
"current" : 0,
"intensity" : 100,
"voltage" : 0
}

Jolt Spec:

{
"operation": "shift",
"spec":{
"ts":"ts",
"sourceDeviceId":"source.deviceId",
"sourceName":"source.name",
"sourceType":"source.type",
"locationLat":"location.lat",
"locationLon":"location.lon",
"locationId":"location.id",
         "recordDate":"recordDate",
"_class":"_class",
"status":"status",
"power":"power",
"current":"current",
"intensity":"intensity",
"voltage":"voltage"
}
}

Please help.

1 ACCEPTED SOLUTION

avatar
Expert Contributor

@RanjitMohapatra 

NiFi expects the Jolt specification to be provided as an array of objects if it's set chain. This is typical when using JoltTransformJSON because it supports multiple transformations chained together. 

Also, if you click on your JoltTransformJSON and click on the advanced option - 

drewski7_1-1729609032503.png


It will bring up a nice Jolt Spec tester for you that is consistent with how NiFi will handle the transformation -

drewski7_0-1729608992995.png

Solution is just wrapping it in an array.

[
{
"operation": "shift",
"spec": {
"ts": "ts",
"sourceDeviceId": "source.deviceId",
"sourceName": "source.name",
"sourceType": "source.type",
"locationLat": "location.lat",
"locationLon": "location.lon",
"locationId": "location.id",
"recordDate": "recordDate",
"_class": "_class",
"status": "status",
"power": "power",
"current": "current",
"intensity": "intensity",
"voltage": "voltage"
}
}
]

Please accept the solution! 

View solution in original post

2 REPLIES 2

avatar
Expert Contributor

@RanjitMohapatra 

NiFi expects the Jolt specification to be provided as an array of objects if it's set chain. This is typical when using JoltTransformJSON because it supports multiple transformations chained together. 

Also, if you click on your JoltTransformJSON and click on the advanced option - 

drewski7_1-1729609032503.png


It will bring up a nice Jolt Spec tester for you that is consistent with how NiFi will handle the transformation -

drewski7_0-1729608992995.png

Solution is just wrapping it in an array.

[
{
"operation": "shift",
"spec": {
"ts": "ts",
"sourceDeviceId": "source.deviceId",
"sourceName": "source.name",
"sourceType": "source.type",
"locationLat": "location.lat",
"locationLon": "location.lon",
"locationId": "location.id",
"recordDate": "recordDate",
"_class": "_class",
"status": "status",
"power": "power",
"current": "current",
"intensity": "intensity",
"voltage": "voltage"
}
}
]

Please accept the solution! 

avatar
Community Manager

@RanjitMohapatra 

Has the reply helped resolve your issue? If so, please mark the appropriate reply as the solution, as it will make it easier for others to find the answer in the future.  Thanks.

 

Regards,

Diana Torres,
Community Moderator


Was your question answered? Make sure to mark the answer as the accepted solution.
If you find a reply useful, say thanks by clicking on the thumbs up button.
Learn more about the Cloudera Community: