Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I am using a tWriteJSONField on my job. I have several string inputs in my schema, but when one of those strings is empty/null it outputs an empty array instead of an empty string. The incoming string is not an array so I am not sure why it is outputing it as such. Can I get it to output an empty string or null at least?
Example:
Rows coming in: Name="Jason", Chair="Lazy", Desk=""
JSON Output:
{ "Name":"Jason", "Chair":"Lazy", "Desk":[] }
twritejsonfield converts rows to JSON output. So it is not a JSON formatting issues since the JSON output component is the one doing the formatting.
After much google searching and community searching this is a bug or "feature" of the java class the component is using. I looked up that specific class and several people are complaining about this "feature" of the class as well. The fact that it treats nulls as arrays is completely nuts, but I guess that is what we have to deal with.
If you are encountering this issue your only solution is to find a way to modify the input or output of the twritejsonfield component to make sure the component either knows they are strings going in or modify them as string coming out.
It may sound nuts, but it is exactly what it does. Multiple people have verified that. Try not to get hung up on what works on the output. My REST call is expecting a string and it is getting an array, it is simply that.
If you send a row with of column value of "" into the twritejsonfield it comes out the other side like this: {column: []}.
If I sent a space " " into the twritejsonfield it comes out the other side like this: {column: " "}.
If I sent a null meaning nothing into the twritejsonfield it comes out the other side like this: {column: []}.
If I sent a 0 into the twritejsonfield it comes out the other side like this: {column: 0}.
If I sent a true into the twritejsonfield it comes out the other side like this: {column: true}.
If I sent a blank boolean into the twritejsonfield it comes out the other side like this: {column: []}.
This can be tested and produces the same result every time in Talend with this component.
i had the same error and the solution is : in the tWriteJSONField component, add an attribute named class then setits static value to Object (right clic on the attribute -> Set a fixed value ). If the value isn't present it will be set to nullna no more the array empty []