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!

Jolt transform use keys as value

avatar
Contributor

Hello, I cannot find an answer on the www to my following question. I have tried splitjson and jolttransform to achieve my desired outcome, but nothing does the trick. My input file looks like this:

 

{
"BVjsoBHDSI" : {
"date" : "2021-04-08",
"description" : "blabla1",
"number" : 40
},
"FudNSk" : {
"date" : "2021-09-26",
"description" : "blabla2",
"number" : 80
},
"Cfjdsl54fd" : {
"date" : "2022-05-10",
"description" : "blablubb",
"number" : 31
}

}

 

Actually I just want to split the stupid thing, but since the root level has a different individual value nifi doesn't understand what I want to do. The idea was to use a jolt transform to add a key "id" with the original key as value. I can't figure out a proper specification though. Glad to hear your ideas.

 

Desired output:

 

{
"BVjsoBHDSI" : {
"date" : "2021-04-08",
"description" : "blabla1",
"number" : 40,

"id" : "BVjsoBHDSI"
},
"FudNSk" : {
"date" : "2021-09-26",
"description" : "blabla2",
"number" : 80,

"id" : "FudNSk"
},
"Cfjdsl54fd" : {
"date" : "2022-05-10",
"description" : "blablubb",
"number" : 31,

"id" : "Cfjdsl54fd"
}

}

 

Then I could easily overwrite the root and split the flowfile as usual.

 

 

 

1 REPLY 1

avatar
Contributor

Idk if it is much of a help, but you can try checking the Jolt Transform quick reference

There's this link to test JOLT specifications.

You can try starting with something like 

[{
  "operation": "shift",
  "spec": {
    "*": "&"
  }
}, {
  "operation": "default",
  "spec": {
    "*": {
      "id": "&(1,0)"
    }
  }
}]