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

Announcements
Write Table now available in Qlik Cloud Analytics: Read Blog
cancel
Showing results for 
Search instead for 
Did you mean: 
Karuetl
Creator II
Creator II

Null Pointer Exception When reading from JSON file

In the JSON file, some rows don't have the column date as below sample

{"id":3,"name":"PRGN","Date_End":"2019-04-08T11:52:45.000Z"}
{"id":9,"name":"FXUL10"}

Below is the logic I am using in the job 

tFileInputDelimited>tExtractJSONFields>tMap>tFileOutputDelimited

 

Date_End is a string data type in the data source

 

In the tMap I used below logic

Then I tried:

(row2.Date_End.equals(""))||(row2.Date_End==null) ? null : 
(TalendDate.parseDate("EEE MMM dd HH:mm:ss Z yyyy",row2.Date_End))

Output Result:

java.lang.NullPointerException

 

Labels (4)
1 Solution

Accepted Solutions
Anonymous
Not applicable

Hi @Karuetl 

 

Could you please try like below?

 

Relational.ISNULL(row2.Date_End) || row2.Date_End.equals("")? null : 
(TalendDate.parseDate("EEE MMM dd HH:mm:ss Z yyyy",row2.Date_End))

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂

View solution in original post

3 Replies
Anonymous
Not applicable

Hello,

What does the output look like from tExtractJSONFields? Could you please use tLogRow behind tExtractJSONFields to print out it on console?

Best regards

Sabrina

PhilHibbs
Creator II
Creator II


Then I tried:

(row2.Date_End.equals(""))||(row2.Date_End==null) ? null : 
(TalendDate.parseDate("EEE MMM dd HH:mm:ss Z yyyy",row2.Date_End))

Swap the order of the End_Date tests so you check ==null first, then it will skip the .equals("") if it's null.

Another way to do the same thing is (row2.Date_End==null ? "" : row2.Date_End).equals("") ? ... which is a bit like a SQL coalesce() function.

Anonymous
Not applicable

Hi @Karuetl 

 

Could you please try like below?

 

Relational.ISNULL(row2.Date_End) || row2.Date_End.equals("")? null : 
(TalendDate.parseDate("EEE MMM dd HH:mm:ss Z yyyy",row2.Date_End))

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂