- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
NIFI Jolt Transformation set change key name based in its value
- Labels:
-
Apache NiFi
Created ‎08-11-2020 02:46 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Created ‎09-19-2020 07:04 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @ammarhassan ,
Please find the below jolt spec:
[
{
"operation": "shift",
"spec": {
"files": {
"*": {
"*-*": {
"$0": "files.&(1,1)File"
}
}
},
"*": "&"
}
}
]
Created on ‎04-07-2023 01:25 AM - edited ‎04-07-2023 01:42 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 "\\"
