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]
Created 03-08-2023 02:44 PM
Hello , can anyone help with a spec to transform this JSON input to the desired output .
JSON INPUT
==========
{
"saleStrategy": {
"strategy": "strategy1",
"code": "code1"
},
"saleStrategyCollection": [
{
"id": "2",
"saleStrategy": {
"strategy": "strategy2",
"code": "code2"
}
},
{
"id": "3",
"saleStrategy": {
"strategy": "strategy3",
"code": "code3"
}
}
]
}
== desired output json ==
{
"saleStrategies" : [
{
"strategy" : "strategy1",
"code" : "code1"
},
{
"strategy" : "strategy2",
"code" : "code2"
},
{
"strategy" : "strategy3",
"code" : "code3"
}
]
}
== current spec === // this currently only transforms the initial single saleStrategy object to an array called salesStrategies. Desired output above shows that If there is a saleStrategy array also present in the input JSON , then the spec needs to add the saleStrategy objects within that array to the salesStrategies output array as well . NOTE the transform must not include "id" in the output.
[
{
"operation": "shift",
"spec": {
"saleStrategy": {
"strategy": "saleStrategies[0].strategy",
"code": "saleStrategies[0].code"
}
}
}
]
Any suggestions would be greatly appreciated. Thanks in advance, Rob.
Created 03-09-2023 08:11 AM
Hi @rob1 ,
Please try the following transformation:
[
// first shift will group all strategies under one collection: saleStrategyCollection
{
"operation": "shift",
"spec": {
"saleStrategyCollection": "&",
"saleStrategy": "saleStrategyCollection[].&"
}
},
// 2ed shift will bucket each strategy & code as an array item ([&2]=0,1,2..)
// under saleStrategies collection and use the same key (&)
{
"operation": "shift",
"spec": {
"saleStrategyCollection": {
"*": { // level 2 = 0,1,2..
"saleStrategy": { //level 1
"strategy": "saleStrategies[&2].&", //level 0
"code": "saleStrategies[&2].&"
}
}
}
}
}
]If that helps, please accept solution.
Thanks
Created 03-08-2023 03:28 PM
@rob1 Welcome to the Cloudera Community!
I noticed that your post may be related to NiFI. To help you get the best possible solution, I have tagged our NiFi experts @MattWho and @SAMSAL who may be able to assist you further.
Please keep us updated on your post, and we hope you find a satisfactory solution to your query.
Regards,
Diana Torres,Created 03-09-2023 12:13 AM
Thanks Diana I'll look out for their reply.
Created 03-09-2023 08:11 AM
Hi @rob1 ,
Please try the following transformation:
[
// first shift will group all strategies under one collection: saleStrategyCollection
{
"operation": "shift",
"spec": {
"saleStrategyCollection": "&",
"saleStrategy": "saleStrategyCollection[].&"
}
},
// 2ed shift will bucket each strategy & code as an array item ([&2]=0,1,2..)
// under saleStrategies collection and use the same key (&)
{
"operation": "shift",
"spec": {
"saleStrategyCollection": {
"*": { // level 2 = 0,1,2..
"saleStrategy": { //level 1
"strategy": "saleStrategies[&2].&", //level 0
"code": "saleStrategies[&2].&"
}
}
}
}
}
]If that helps, please accept solution.
Thanks
Created 03-11-2023 11:00 AM
Hi Samsal - that's perfect. Many thanks , Rob 👍