Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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:
But the same job returns the following when there's only one record in the response:
Obviously these are different and we don't want our API consumers to deal with this difference.
This is my tWriteJSONField component:
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)?
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.
@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!
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...