Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

unable to split array elements to individual objects using Jolt

avatar
Rising Star

             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

1 ACCEPTED SOLUTION

avatar

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.

View solution in original post

4 REPLIES 4

avatar
Rising Star

@SAMSAL , Could you please help on this

avatar

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.

avatar
Rising Star

thank you so much for the quick help @SAMSAL .

avatar
Rising Star

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