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!

unable to split array elements to individual objects using Jolt

avatar
Expert Contributor

             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
Super Guru

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
Expert Contributor

@SAMSAL , Could you please help on this

avatar
Super Guru

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
Expert Contributor

thank you so much for the quick help @SAMSAL .

avatar
Expert Contributor

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