Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
jkrfs
Creator
Creator

[resolved] Empty/Null fields show up in json output twritejsonfield

I have a flow going into tWriteJsonFIELD which creates an array
{docs:}
However, if lets say the date is missing in one of the fields, it looks like this:
{docs:}
]}
Which is not what I want. If the field is empty/null I do not want it to show up in the output at all, like so:
{docs:}
Does anyone have any advice or ideas on how I can achieve this?
Thank you!
Labels (3)
1 Solution

Accepted Solutions
Anonymous
Not applicable

Hi
It is impossible to generate the result as you expected by modifying anything on tWriteJasonField, try to replace null with another date or handle the string further after tWriteJasonField, for example, replace all the string ",\"date\":[]"with empty string.
Shong

View solution in original post

9 Replies
Anonymous
Not applicable

Hi
It is impossible to generate the result as you expected by modifying anything on tWriteJasonField, try to replace null with another date or handle the string further after tWriteJasonField, for example, replace all the string ",\"date\":[]"with empty string.
Shong
jkrfs
Creator
Creator
Author

Good thinking Shong, I like the idea of just searching for the whole field and removing it altogether.
Thanks!
jkrfs
Creator
Creator
Author

I added a tJavaRow after tWriteJSONField and did this:
output_row.output = input_row.output.replaceAll(",\"*\":\\", "");
Works like a charm.
Anonymous
Not applicable

I added a tJavaRow after tWriteJSONField and did this:
output_row.output = input_row.output.replaceAll(",\"*\":\\", "");
Works like a charm.

Cool, thanks for your feedback and the solution.
Shong
Anonymous
Not applicable

BTW, for those, who faced similiar problem:
regex provided by jkrfs works for his case, but will not work if you have fields with underscore character or digits in name. Use this instead:
replaceAll(",?\"*\":\\", "");
Anonymous
Not applicable

BTW, for those, who faced similiar problem:
regex provided by jkrfs works for his case, but will not work if you have fields with underscore character or digits in name. Use this instead:
replaceAll(",?\"*\":\\", "");

Hi Andrey 
Thanks for offering a more comprehensive expression.
Best regards
Shong
_AnonymousUser
Creator III
Creator III

I have a flow going into tWriteJsonFIELD which creates an array
{docs:}
However, if lets say the date is missing in one of the fields, it looks like this:
{docs:}
]}
Which is not what I want. If the field is empty/null I do not want it to show up in the output at all, like so:
{docs:}
Does anyone have any advice or ideas on how I can achieve this?
Thank you!

Hi,
How did you achieve the below using the twriteJson, Please assist. 
{docs:}

Thanks,
Anonymous
Not applicable

Hi,
How did you achieve the below using the twriteJson, Please assist. 
{docs:}

Thanks,

Hello Naina
It seems your problem is not related to this subject. In order to better manage and follow up your questions, please report a topic for your question. 
Regards
Shong
Anonymous
Not applicable

I'm wondering how the behavior reported here isn't a bug. When the values are empty, how does it make sense to convert it to []? This is especially bad because, at the opposite end, tExtractJSONFields doesn't recognize those [], and either turns it into a literal string of "[]" or (for numbers) throws an exception. I added this hack, and it's working. Is there no option to avoid the hack?