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!

NiFi Jolttransform to package json array into object?

avatar
Explorer

i have json array like the following: [{"id":"one"}, {"id,"two"}] Any idea how could i "package" it into json "root" like the following: { [{"id":"one"}, {"id,"two"}] }

I am trying to use JolttransformJSON but couldn't find any clues how to approach operation like this....

Thank you

1 ACCEPTED SOLUTION

avatar
Master Guru

I don't think your desired output is valid JSON, as the root object only has an array in it, not a key/value pair. If you want a key in there (let's call it root) the following spec will work in JoltTransformJSON:

[
  {
    "operation": "shift",
    "spec": {
      "*": "root.[]"
    }
  }
]


Otherwise if you just want to add braces around the array, you can use ReplaceText, replacing the entire thing with {$1}

View solution in original post

2 REPLIES 2

avatar
Master Guru

I don't think your desired output is valid JSON, as the root object only has an array in it, not a key/value pair. If you want a key in there (let's call it root) the following spec will work in JoltTransformJSON:

[
  {
    "operation": "shift",
    "spec": {
      "*": "root.[]"
    }
  }
]


Otherwise if you just want to add braces around the array, you can use ReplaceText, replacing the entire thing with {$1}

avatar
Explorer

how can i transform array of maps into array of values: ["one", "two", "three"] ?