Support Questions

Find answers, ask questions, and share your expertise

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)"
    }
  }
}]