Search code examples
jsontalend

Talend - Convert String to JSON string array


I am using Talend Studio for data integration to process data. The data are stored in xml file, then are converted to JSON file. One of columns (partners) is a String element delimited by ";" separator.

example : "partner1;partner2;partner3"

expected result : ["partner1","partner2","partner3"]

Is there any Talend functon to do this? or can I use java functions ?


Solution

  • Working with Json data in Talend is quite complicated. You can achieve what you want with Talend components, but workflow is not so simple.

    enter image description here

    1. tFileInputXML : extract data from your xml
    2. tNormalize : normalize the column where you have multiple occurences (here I used ";" as a separator). Number of rows in the output is the number of element in your column (in your example : 3)
    3. tMap : I mapped my column, and added a fixed field "loop" for the next component enter image description here
    4. tWriteJsonField : here you have to use attributes and loops to get an array. see screenshot. enter image description here enter image description here

    Your question is quite simple, but the resolution is not. If someone has a better way to do it, I am curious to see it.