Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I have a job with steps very similar to this post:
https://help.talend.com/r/en-US/8.0/processing/twritejsonfield-tmap-trowgenerator-trowgenerator-converting-rows-to-json-array-to
Records come in to tWriteJSONField and a json structure comes out. When I have multiple records coming in, it works great! Well, almost great.
However, when I have a single record coming in, the "dummyloop" is getting included in the json output.
Here's what it looks like with multiple rows being processed
{"name":"Step 1 - Provider Load","condition":"ALL_SUCCEEDED","taskIds":["65537ffddb7ce63c035f90da"]},
{"name":"Step 2 - Provider Network Load","condition":"ALL_SUCCEEDED","taskIds":["6553800006cc172dd0b1f95d"]},
{"name":"Step 3 - Member Load","condition":"ALL_SUCCEEDED","taskIds":["65538002db7ce63c035f90dc"]}
Here's what it looks like with a single row being processed
"dummyloop": {
"name": "Step 1 - Code Load","condition": "ALL_SUCCEEDED","taskIds": ["65537425c995e015ec5ededf"]}
}
Why would tWriteJSONField behave differently for one record vs multiple? Any ideas on how to fix this? I could add in a replace function to get rid of the dummyloop, but it doesn't seem like I should have to do this.
Thanks for any ideas.
I figured out my problem, so here is my solution in case this helps anyone else. I wasn't truly setting up the json tree the way it needs to be set up. I was only doing a part of my structure and then using tJava to string together the rest of it. This post really helped me sort things out:
https://stackoverflow.com/questions/74800427/how-to-create-two-nested-array
Although my example isn't exactly like theirs, it gave me hints and through trial and error I figured out how to make it work.
Whether I have a single result of multiple results it gives me the desired json structure that I'm looking for:
{"name":"All_Clients_NDC_Load","workspaceId":"6532a0fd924af6792a34f982","description":"Loads NDC codes",
"steps":[
{"name":"Step 1 - NDC Code Load","condition":"ALL_SUCCEEDED","taskIds":["65537425c995e015ec5ededf"]},
{"name":"Step 2 - NDC Code Load","condition":"ALL_SUCCEEDED","taskIds":["65537425c995e015ec5ededg"]},
{"name":"Step 3 - NDC Code Load","condition":"ALL_SUCCEEDED","taskIds":["65537425c995e015ec5ededh"]}
]
}
{"name":"All_Clients_NDC_Load",
"workspaceId":"6532a0fd924af6792a34f982",
"description":"Loads NDC codes",
"steps":[
{"name":"Step 1 - NDC Code Load","condition":"ALL_SUCCEEDED","taskIds":["65537425c995e015ec5ededf"]}]}