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!

add outside value to array using jolt

avatar
Expert Contributor

Hi All,

Could you please help in getting below value to be splitted across the array , the value outside of arrray

 

Input:

{

"DatiRiepilogo": {
"Natura": "N3.5",
"AliquotaIVA": [
"22.00",
"5.00"
],
"ImponibileImporto": [
"215.43",
"6.70"
],
"Imposta": [
"47.39",
"0.34"
]
}
}

 

SPEC:

[

{
"operation": "shift",
"spec": {

"DatiRiepilogo": {
"Natura":{

"*":{
"@(2,Natura)": "FatturaElettronicaBody.DatiBeniServizi.DatiRiepilogo[&1].Natura"

}},

"AliquotaIVA": {

"@": "FatturaElettronicaBody.DatiBeniServizi.DatiRiepilogo[&1].AliquotaIVA",
"*": {
"@": "FatturaElettronicaBody.DatiBeniServizi.DatiRiepilogo[&1].AliquotaIVA"
}
},
"ImponibileImporto": {
"@": "FatturaElettronicaBody.DatiBeniServizi.DatiRiepilogo[&1].ImponibileImporto",
"*": {
"@": "FatturaElettronicaBody.DatiBeniServizi.DatiRiepilogo[&1].ImponibileImporto"
}
},
"Imposta": {
"@": "FatturaElettronicaBody.DatiBeniServizi.DatiRiepilogo[&1].Imposta",
"*": {
"@": "FatturaElettronicaBody.DatiBeniServizi.DatiRiepilogo[&1].Imposta"
}
}
}
}
}
]

 

Expected Output:

{
"FatturaElettronicaBody" : {
"DatiBeniServizi" : {

"DatiRiepilogo" : [ {

"Natura": "N3.5",
"AliquotaIVA" : "22.00",
"ImponibileImporto" : "215.43",
"Imposta" : "47.39"
}, {

"Natura": "N3.5",
"AliquotaIVA" : "5.00",
"ImponibileImporto" : "6.70",
"Imposta" : "0.34"
} ]
}
}
}

 

@SAMSAL , @MattWho  Could you please help on this

1 ACCEPTED SOLUTION

avatar
Super Guru

Hi @PradNiFi1236 ,

Is the following spec what you are looking for:

[

  {
    "operation": "shift",
    "spec": {
      "DatiRiepilogo": {
        "AliquotaIVA": {
          "*": {
            "@(2,Natura)": "FatturaElettronicaBody.DatiBeniServizi.DatiRiepilogo[&1].Natura",
            "@": "FatturaElettronicaBody.DatiBeniServizi.DatiRiepilogo[&1].AliquotaIVA"
          }
        },
        "ImponibileImporto": {
          "*": {
            "@": "FatturaElettronicaBody.DatiBeniServizi.DatiRiepilogo[&1].ImponibileImporto"
          }
        },
        "Imposta": {
          "*": {
            "@": "FatturaElettronicaBody.DatiBeniServizi.DatiRiepilogo[&1].Imposta"
          }
        }
      }
    }
}
]

 

View solution in original post

3 REPLIES 3

avatar
Super Guru

Hi @PradNiFi1236 ,

Is the following spec what you are looking for:

[

  {
    "operation": "shift",
    "spec": {
      "DatiRiepilogo": {
        "AliquotaIVA": {
          "*": {
            "@(2,Natura)": "FatturaElettronicaBody.DatiBeniServizi.DatiRiepilogo[&1].Natura",
            "@": "FatturaElettronicaBody.DatiBeniServizi.DatiRiepilogo[&1].AliquotaIVA"
          }
        },
        "ImponibileImporto": {
          "*": {
            "@": "FatturaElettronicaBody.DatiBeniServizi.DatiRiepilogo[&1].ImponibileImporto"
          }
        },
        "Imposta": {
          "*": {
            "@": "FatturaElettronicaBody.DatiBeniServizi.DatiRiepilogo[&1].Imposta"
          }
        }
      }
    }
}
]

 

avatar
Expert Contributor

Thank you So much @SAMSAL ,

if the input is array of values then its coming good, How about if input is  nonarray value something like this
{
"DatiBeniServizi": {
"DatiRiepilogo": {
"AliquotaIVA": "22.00",
"ImponibileImporto": "367.94",
"Imposta": "80.95"
}
}

 

i think without [&1] will work but how to accept both nonarray and array input using single spec?
}

avatar
Super Guru

I dont think you can use the same jolt spec for two different schema. Jolt spec doesnt allow you to use the same key multiple times. You have to know beforehand what schema are you getting then direct to different jolt transformation processor , or store the spec dynamically in an attribute to pass it to single jolt processor