Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Data Works for AI is here - Join the discussion and enter to win a pair of Qlik kicks: Join the Conversation!
cancel
Showing results for 
Search instead for 
Did you mean: 
JackieM
Contributor II
Contributor II

Output JSON array that behaves the same with one record or multiple records

We're using Talend to create an API and want the response message from tRESTResponse to be in the format:

[ { }, { } ] for multiple records or [ { } ] for one record.

Using the information from the Help section (Configuring and running the Job | Talend Components for Jobs Help), I was able to set up a job that gives me the output I want when there's more than one record in the response:

JackieM_0-1782502023701.png

But the same job returns the following when there's only one record in the response:

JackieM_1-1782502059626.png

Obviously these are different and we don't want our API consumers to deal with this difference.

This is my tWriteJSONField component:

JackieM_2-1782502279849.png

 

JackieM_3-1782502300680.png

Is there any way to make this work with Talend or do I have to write custom code to deal with this situation (which would be extremely frustrating)?

Talend Data Integration Talend Studio 

Labels (3)
3 Replies
DaniZ
Partner - Contributor III
Partner - Contributor III

As this looks like a straightforward Text to JSON conversion - you should be able to use tFileOutputJSON to get what you need. Make sure that "Generate as array json" is checked.

I DO agree that the tWriteJSONField behavior feels bugged to me as well. It should behave more consistently and have the same explicit array option. I hope someone from support can take a look at that component's behavior and maybe open a ticket to fix it.

JackieM
Contributor II
Contributor II
Author

@DaniZ Thank you so much!  The tFileOutputJSON indeed does exactly what I need!  This makes it more puzzling why tWriteJSONField doesn't behave the same way.

I'll have the extra step of needing to clean up the file since I'm basically writing to the file, opening it and then passing the results to tRestRepsonse.  Again it would be much simpler if tWriteJSONField handled and I could keep it all within the data flow without having to bring a file into it.

Thank you so much for your response!

DaniZ
Partner - Contributor III
Partner - Contributor III

If you have the time, maybe you could open a case to support and inquire about this behavior or if they claim that this is a feature rather than a bug, maybe open an Ideation request to get this component properly aligned...