Handling Java time stamps (longs) in a tWriteJSONField

Six Stars

Handling Java time stamps (longs) in a tWriteJSONField

I'm trying to write Java timestamps out to a JSON object using tWriteJSONField, and not getting very far.

 

Not setting the type attribute yields the timestamp in a quoted string (E.g., "1531434936872")

Setting the type attribute to "integer" yields a NumberFormatException

Setting the type attribute to "number" turns the timestamp into a double (E.g., 1.531434846295E12)

Setting the type attribute to "object" yields an empty object ("{}")

 

Is there a way to handle this?

Highlighted
Moderator

Re: Handling Java time stamps (longs) in a tWriteJSONField

Hello,

Could you please elaborate your case with an example with input and expected output values?

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: Handling Java time stamps (longs) in a tWriteJSONField

Given this simple job:

 

JsonJob.PNG

Where the row generator queries the current system time like this

randomRowTs.PNG

And the JSON tree in tWriteJSONField is configured like this:

JsonTree.PNG

I get the following output:

Starting job TestJavaTimestamp at 09:18 16/07/2018.

[statistics] connecting to socket on port 3627
[statistics] connected
{"currentTime":1.531757903116E12}
[statistics] disconnected
Job TestJavaTimestamp ended at 09:18 16/07/2018. [exit code=0]

I would expect output like this:

{"currentTime":1531757892465}

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 2

Part 2 of a series on Context Variables

Blog

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