Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello everyone,
I'm trying to send a json with a tRestClient, but I need to construct the payload first.
The Json is constructed by joining an ID and list of strings coming from another job (passed through context), a second list also coming from another job (passed through context) and a third the result of a sql query.
Since I can't use tWriteJsonFields with more than one loop element I tried to do it with a tXmlMap, but so far I couldn't get the whole combination. When I put loop on od_pairs, discount_codes and bucket_codes (see schema below) I get all the possible combination. Whereas, I would like to loop through each list, add their elements to the corresponding column and just add the three lists to my output
This is what my inputs look like:
ID: "TRES2022_UII" (string)
List_1: "[
"RE_BAMBIN","RE_SAPA","RE_ELIXIR20"
]" (a String that I normalize in order to get each value)List_2: "[
"PA_A","PA_B","PA_C"
]" (a String that I normalize in order to get each value)query results (two columns): 98745231; 65821365|65824365; 65821367|65827765; 65821344
Final output should look like this in Json:
{
"tariff_code": "ID",
"od_pairs": [
{
"origin_code": "98745231",
"destination_code": "65821365"
},
{
"origin_code": "65824365",
"destination_code": "65821367"
}
{
"origin_code": "65827765",
"destination_code": "65821344"
}
],
"bucket_codes": [
"RE_BAMBIN",
"RE_SAPA",
"RE_ELIXIR20"
],
"discount_codes": [
"PA_A",
"PA_B",
"PA_C"
]
}
Is there a way to achieve that using tXmlMAP or maybe another simpler method?
There are a couple of things to raise here. First, and arguably why you are not getting the XML in the format you expect, you do not have your Main Row linked to your lookups. You will need a link to be here and I suspect that this is why you are getting all possible permutations. I suspect that this will require some sort of key data to be included linking each of the lookups....although I do see that you have already linked the lookups to each other. So maybe just a key to one of the lookups from Main.
The other thing is, how will you convert from XML to JSON? This can be done, but it will require some thought to get it to be in the correct format for your API. Does your API accept XML as well as JSON? This could simplify things.
I almost forgot to ask, but are you using the "free" version of Talend or do you have a contract with us? If you are using the paid version, there is the Data Mapper which might make this more straight forward.