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

Highlighted
Six 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?    


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.

View solution in original post

Six 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.

View solution in original post


All 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
Six 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.

View solution in original post

Six 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.

View solution in original post

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.
Six 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 

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog