Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]

Support Questions

Find answers, ask questions, and share your expertise
Announcements
Share your experience with Cloudera on G2 and get a $25 Amazon Gift card.
Hi, I'm CLEO! Something exciting is coming to the Community. Stay Tuned!

want to add new variable into my json on NIFI

avatar
Explorer

so i am working on NIFI and we are converting and sorting our .asn file into json file so right now for this i am using some processors 

Ashi_0-1724735800731.png

this all processors i am using , now i want to change  name of existing variable into input file means i am having 2 resultcode in my input file and output is coming like this resultcode = {2001,2001} now i want the second value to come under resultcodemscc what processor i can use here ? my input after jolt looks like                                           "sessionStopTime" : "09/07/2024 06:47:19",
"resultCode" : [ "2001", "2001" ],
"recordOpeningTime" : "09/07/2024 06:44:22"

 

this is all live data i cant hardcode the value , pls suggest something ASAP !

3 REPLIES 3

avatar
Super Guru

Hi,

Its not clear from your description what is the input json format and what is the expected output format, but from what I was able to understand from your description you have the following json:

{
	"sessionStopTime": "09/07/2024 06:47:19",
	"resultCode": [
		"2001",
		"2001"
	],
	"recordOpeningTime": "09/07/2024 06:44:22"
}

And you want to produce new attribute for the second array element of resutltCode to be stored in another field like this even though in your case both array elements are the same:

 

{
	"sessionStopTime": "09/07/2024 06:47:19",
	"resultCode": [
		"2001",
		"2001"
	],
	"resultcodemscc":"2001",
	"recordOpeningTime": "09/07/2024 06:44:22"
}

If this the case then Jolt spec would look like this:

 

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "resultcodemscc": "=elementAt(@(1,resultCode),1)"
    }
  }
]

 

If that helps please accept solution.

Thanks

avatar
Explorer

so this is my input data for jolt transformer 

{
"recordType" : "OC",
"recordElements" : [ {
"varName" : "preame",
"varValue" : "z"
}, {
"varName" : "recdId",
"varValue" : "2024b"
}, {
"varName" : "genertamp",
"varValue" : "09/07/2024 06:47:19"
}, {
"varName" : "sesnId",
"varValue" : "dd"
"varName" : "servitextId",
"varValue" : "322p.org"
}, {
"varName" : "requestType",
"varValue" : "TEST"
}, {
"varName" : "nccVersion",
"varValue" : "SPS3_R1"
}, {
"varName" : "RecordTimestamp",
"varValue" : "09/0:19"
} ],
"recordExtensions" : [ {
"recordProperty" : "listOfSubonID",
"recordElements" : null,
"recordSubExtensions" : [ {
"recordProperty" : "subscrinId",
"recordElements" : [ {
"varName" : "subscrinIdType",
"varValue" : "1"
}, {
"varName" : "subscriptionIdData",
"varValue" : "219014523"
} ],
"recordSubExtensions" : null
}, {
"recordProperty" : "subscriptionId",
"recordElements" : [ {
"varName" : "subscriptionIdType",
"varValue" : "0"
}, {
"varName" : "subscriptionIdData",
"varValue" : "385993101133"
} ],
"recordSubExtensions" : null
} ]
}, {
"recordProperty" : "listOfMscc",
"recordElements" : null,
"recordSubExtensions" : [ {
"recordProperty" : "mscc",
"recordElements" : [ {
"varName" : "ratingGroup",
"varValue" : "40"
}, {
"varName" : "serviceIdentifier",
"varValue" : "100"
}, {
"varName" : "chargingType",
"varValue" : "ONLRGING"
}, {
"varName" : "recordEventType",
"varValue" : "PS"
}, {
"varName" : "reportReason",
"varValue" : "FINAL"
}, {
"varName" : "firstDataStart",
"varValue" : "09/044:22"
}, {
"varName" : "lastDataUsage",
"varValue" : "09/0:47:19"
}, {
"varName" : "timeUsage",
"varValue" : "177"
}, {
"varName" : "usedUnitType",
"varValue" : "TL"
}, {
"varName" : "resultCode",
"varValue" : "2001"
}, {
"varName" : "downnsumed",
"varValue" : "41619"
} ],

and if you can see i have 2 result code 1st at the starting and another 1 is under mscc and i am getting output of this as both coming under resultcode like resultcode {2001,2001 } but i want 2nd one will come like resultcodemscc = 2001 here is my jolt spec and output of that  jolt spec ------

[
{
"operation": "shift",
"spec": {
"recordType": "recordType",
"recordElements": {
"*": {
"varValue": "@(1,varName)"
}
},
"recordExtensions": {
"*": {
"recordProperty": "&",
"recordSubExtensions": {
"*": {
"recordProperty": "&",
"recordElements": {
"*": {
"varValue": "@(1,varName)"
}
}
}
},
"recordSubExtensions": {
"*": {
"recordProperty": "&",
"recordElements": {
"*": {
"varValue": "@(1,varName)"
}
},
"recordSubExtensions": {
"*": {
"recordProperty": "&",
"recordSubExtensions": {
"*": {
"recordProperty": "&",
"recordElements": {
"*": {
"varValue": "@(1,varName)"
}
},
"recordSubExtensions": {
"*": {
"recordProperty": "&",
"recordElements": {
"*": {
"varValue": "@(1,varName)"
}
},
"recordSubExtensions": {
"*": {
"recordProperty": "&",
"recordElements": {
"*": {
"varValue": "@(1,varName)"
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
]

 

and output is coming like

"resultCode" : [ "2001", "2001" ],

avatar
Explorer

varValue: 02F210
- varName: rATType
varValue: '2'
- varName: resultCode
varValue: '2001'
- varName: recordOpeningTime

 

this is the 1st resultcode present at starting