Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

NIFI Jolt Transformation set change key name based in its value

avatar
New Contributor

Hi,

I am trying to change the key name based on the value it contains. I need help in transforming the output based in the following input JSON 

 

{
"id": "3240",

"files" : {
"FileName3": "mac-20200806.json",
"FileName2": "window-20200806.json",
"FileName1": "linux-20200806.json"

 }
}

Output

{
"id": "3240",

"files" : {
"macFile": "mac-20200806.json",
"windowFile": "window-20200806.json",
"linuxFile": "linux-20200806.json"

 }
}

 

There can be any number for files but the file name will always start with mac, windows or Linux

 

2 REPLIES 2

avatar
Expert Contributor

Hi @ammarhassan ,
Please find the below jolt spec:

[
{
"operation": "shift",
"spec": {
"files": {
"*": {
"*-*": {
"$0": "files.&(1,1)File"
}
}
},
"*": "&"
}
}
]

 

avatar
Contributor

Hello, is there such a thing as an escape character? I would need keynames with a "." in it. In this example something like:

 

Output

{
"id": "3240",

"files" : {
"mac.File": "mac-20200806.json",
"window.File": "window-20200806.json",
"linux.File": "linux-20200806.json"

 }
}

 

But dots are interpreted as nesting objects. Thanks

 

Edit: Nevermind, I found we can use escape characters with "\\"