Five Stars

How to create json output to file retaining non-string data types

I have a job where I am trying to transform a csv input file to create a json output to file.

The csv file contains string values as well as integer values. However it produces all values as string (between quotes) even when the data types are not string i.e. integer value 123456789 as "123456789".

 

My job has the following components 

 

tFileInputDelimited >>tMap>>tWriteJSONField>>tLogRow>>tFileOutputDelimited

 

Is there a simple way of doing this?    

Tags (1)
2 ACCEPTED SOLUTIONS

Accepted Solutions
Ten Stars

Re: How to create json output to file retaining non-string data types

@ThirupathiReddy is using tFileOutputJSON rather than tWriteJSONField.  Here is the documentation for tWriteJSONField:

https://help.talend.com/reader/wDRBNUuxk629sNcI0dNYaA/ZXYb2NIVoiib7B8sYGRVJQ

 

The section on Configuring a JSON Tree addresses your issue specifically.

Five Stars

Re: How to create json output to file retaining non-string data types

Thanks but it does not produce the json in the format that I need.

 

I have created a work-around by building the json as variables in a tMap and concatenating the variables together and writing to a file with .json extension, this does the trick for me.

6 REPLIES
Five Stars

Re: How to create json output to file retaining non-string data types

 

Input and tFileOutputJson components is enough for this task.

in tFileOutputJson component if we have int as datatype then we will get with out quotes for integer values.

 

See attached screenshots.

Thiru
Five Stars

Re: How to create json output to file retaining non-string data types

Thanks but what I am trying to do is take in a csv file and transform it into a json file.

 

I have an example below...

This is the sample file
create_json_retain_datatypes.PNG

 

 

 

 

 

 

 

 

 

 

In the tMap the person_id is converted from string to an integer create_json_retain_datatypes2.PNG

 

 

 

 

 

 

 

 

 

 

 

However when I execute my job it writes out person_id value as a string  (see log output below)create_json_retain_datatypes3.PNG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Is there a way to solve this?

Ten Stars

Re: How to create json output to file retaining non-string data types

@ThirupathiReddy is using tFileOutputJSON rather than tWriteJSONField.  Here is the documentation for tWriteJSONField:

https://help.talend.com/reader/wDRBNUuxk629sNcI0dNYaA/ZXYb2NIVoiib7B8sYGRVJQ

 

The section on Configuring a JSON Tree addresses your issue specifically.

Five Stars

Re: How to create json output to file retaining non-string data types

Thanks but it does not produce the json in the format that I need.

 

I have created a work-around by building the json as variables in a tMap and concatenating the variables together and writing to a file with .json extension, this does the trick for me.

Moderator

Re: How to create json output to file retaining non-string data types

Hello,

 I have created a work-around by building the json as variables in a tMap and concatenating the variables together and writing to a file with .json extension, this does the trick for me.

Would you mind posting your work around and solution on forum?

 

Best regards

Sabrina

--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
Five Stars

Re: How to create json output to file retaining non-string data types

I revisited @cterenzi suggestion and have got my job working. 

 

create_json_retain_datatypes4.PNGcreate_json_retain_datatypes5.PNG

Thanks