Skip to main content
PradNiFi1236
Gold ⭐️
May 8, 2023
Solved

unable to split array elements to individual objects using Jolt

             i'm trying to split the array values to seperate list of object values but not able to get it.

input:

{
"FatturaElettronicaBody": {
"DatiGenerali": {
"DatiGeneraliDocumento": {
"TipoDocumento": "TD01",
"Numero": "126561",
"Data": "05.05.2023",
"Divisa": "EUR",
"ImportoTotaleDocumento": "9382.29"
},
"DatiDDT": {
"NumeroDDT": "086708,086704,086705,086706,086707"
}
}
}
}

 

using spec:

[

{
"operation": "shift",
"spec": {
"FatturaElettronicaBody": {
"DatiGenerali": {
"DatiDDT": {
"*": {
"NumeroDDT": "FatturaElettronicaBody.DatiGenerali.DatiDDT[&1].NumeroDDT"
}
}
}
}
}
}

]

 

but getting result as null.

 

expected output:

{
"FatturaElettronicaBody": {
"DatiGenerali": {
"DatiGeneraliDocumento": {
"TipoDocumento": "TD01",
"Numero": "126561",
"Data": "05.05.2023",
"Divisa": "EUR",
"ImportoTotaleDocumento": "9382.29"
},
"DatiDDT": {
"NumeroDDT":{

"086708

},

"NumeroDDT":{

086704

},

"NumeroDDT":{

086705

},

"NumeroDDT":{

086706

},

"NumeroDDT":{

086707"

}
}
}
}
}

 

 

 

 

Regards,

Pradeep

SAMSAL
SAMSALAnswer
Platinum ⭐️⭐️⭐️
May 8, 2023

Hi,

I believe this spec would help with setting the date as default date in each array element:

 

[
{
"operation": "modify-overwrite-beta",
"spec": {
"FatturaElettronicaBody": {
"DatiGenerali": {
"DatiDDT": {
"NumeroDDT": "=split('[,]',@(1,NumeroDDT))"
}
}
}
}
},
{
"operation": "shift",
"spec": {
"FatturaElettronicaBody": {
"DatiGenerali": {
"DatiGeneraliDocumento": "FatturaElettronicaBody.DatiGenerali.&",
"DatiDDT": {
"NumeroDDT": {
"*": {
"@": "FatturaElettronicaBody.DatiGenerali.DatiDDT[&1].NumeroDDT",
"@(3,DatiGeneraliDocumento.Data)": "FatturaElettronicaBody.DatiGenerali.DatiDDT[&1].Date"
}
}
}
}
}
}
}
]

If that helps please accept solution.

4 replies

PradNiFi1236
Gold ⭐️
May 8, 2023

@SAMSAL , Could you please help on this

Translate
SAMSAL
SAMSALAnswer
Platinum ⭐️⭐️⭐️
May 8, 2023

Hi,

I believe this spec would help with setting the date as default date in each array element:

 

[
{
"operation": "modify-overwrite-beta",
"spec": {
"FatturaElettronicaBody": {
"DatiGenerali": {
"DatiDDT": {
"NumeroDDT": "=split('[,]',@(1,NumeroDDT))"
}
}
}
}
},
{
"operation": "shift",
"spec": {
"FatturaElettronicaBody": {
"DatiGenerali": {
"DatiGeneraliDocumento": "FatturaElettronicaBody.DatiGenerali.&",
"DatiDDT": {
"NumeroDDT": {
"*": {
"@": "FatturaElettronicaBody.DatiGenerali.DatiDDT[&1].NumeroDDT",
"@(3,DatiGeneraliDocumento.Data)": "FatturaElettronicaBody.DatiGenerali.DatiDDT[&1].Date"
}
}
}
}
}
}
}
]

If that helps please accept solution.

Translate
PradNiFi1236
Gold ⭐️
May 8, 2023

thank you so much for the quick help @SAMSAL .

Translate
PradNiFi1236
Gold ⭐️
May 17, 2023

in Addition to above logic , if the input payload comes as below with number and Date combined in single array field.

input:

{
"FatturaElettronicaBody": {
"DatiGenerali": {
"DatiGeneraliDocumento": {
"TipoDocumento": "TD01",
"Numero": "126587",
"Data": "16.05.2023",
"Divisa": "EUR",
"ImportoTotaleDocumento": "7011.10"
},
"DatiDDT": [
{
"NumeroDDT": "126681-15.05.2023"
},
{
"NumeroDDT": "12680-10.05.2023"
}
]
}
}
}

 

Used the spec below:

[
{
"operation": "modify-overwrite-beta",
"spec": {
"FatturaElettronicaBody": {
"DatiGenerali": {
"DatiDDT": {
"*": {
"b_NumeroDDT": "=split('[-.]',@(1,NumeroDDT))",
"NumeroDDT": "@(1,b_NumeroDDT[0])",
"DataDDT": "=concat(@(1,b_NumeroDDT[3]),'-',@(1,b_NumeroDDT[2]),'-',@(1,b_NumeroDDT[1]))"
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"FatturaElettronicaBody": {
"DatiGenerali": {
"DatiGeneraliDocumento": "FatturaElettronicaBody.DatiGenerali.&",
"DatiDDT": {
"*": {
"NumeroDDT": "FatturaElettronicaBody.DatiGenerali.DatiDDT[&1].NumeroDDT",
"DataDDT": "FatturaElettronicaBody.DatiGenerali.DatiDDT[&1].Date"
}
}
}
}
}
}
]

 

 

Output:

 

{
"FatturaElettronicaBody" : {
"DatiGenerali" : {
"DatiGeneraliDocumento" : {
"TipoDocumento" : "TD01",
"Numero" : "126587",
"Data" : "16.05.2023",
"Divisa" : "EUR",
"ImportoTotaleDocumento" : "7011.10"
},
"DatiDDT" : [ {
"NumeroDDT" : "126681",
"Date" : "2023-05-15"
}, {
"NumeroDDT" : "12680",
"Date" : "2023-05-10"
} ]
}
}
}

Translate