Skip to main content
PradNiFi1236
Gold ⭐️
October 10, 2023
Solved

add outside value to array using jolt

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

SAMSAL
SAMSALAnswer
Platinum ⭐️⭐️⭐️
October 10, 2023

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

 

3 replies

SAMSAL
SAMSALAnswer
Platinum ⭐️⭐️⭐️
October 10, 2023

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

 

Translate
PradNiFi1236
Gold ⭐️
October 10, 2023

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?
}

Translate
SAMSAL
Platinum ⭐️⭐️⭐️
October 10, 2023

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

Translate