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

Announcements
Qlik Connect 2026 Agenda Now Available: Explore Sessions
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Handling nulls for integer columns while creating JSON for tMongoDBOutput

Hi, 

I am generating the JSON structure to insert to my MongoDB using tMongoDBOutput stage. In the Configure JSON Tree, I have specified attribute "type" as integer for the Integer fields.But the job is failing when NULL values are incoming from the source. My source is a SQL server DB.0683p000009Lss9.jpg

 

0683p000009Ltk1.jpg

Can anyone assist on this please.

Thanks,

sr

Labels (3)
10 Replies
Sid3
Contributor III
Contributor III

Sr,

This is a number format exception. which means " "(one space as value) cannot insert this value in integer as it is a string.

Seems you are directly converting a string to Integer. Treat both fields as string then add a tMap after this and apply the below function.

in Tmap target flow define both these fiedls as Integers.

 
row1.EMPID != null ? new Integer(row1.EMPID.trim()) : Integer.valueOf("")

repeat the same for Dept id in expression editor.

 

 

Thanks,
Sid
Please like the post if it is useful
Please put to Solved if it resolves your issue.

Anonymous
Not applicable
Author

Thanks for your response. But I have NULL in my input ( like NULL as EmpID from SQL server and outing to an Integer column ) and am creating this JSON tree for MongoDB insert. My Job design is tMSSQLInput-> tMongoDBOutput. The NULL is being converted to "" internally to Job when it tries to convert the input to JSON format.

Thanks,

sr

Sid3
Contributor III
Contributor III

Do you mean NULL as string or a NULL object. Lot of difference here.

 

if NULL as string then use below logic

 

row1.EMPID != null && row1.EMPID.equalsIgnoreCase("NULL") ? new Integer(row1.EMPID.trim()) : Integer.valueOf("")

Anonymous
Not applicable
Author

Its NULL as an object

Anonymous
Not applicable
Author

I am having the same issue, was this ever resolved or a solution found?

Anonymous
Not applicable
Author

Same problem here

Anonymous
Not applicable
Author

Hello,

Have you tried to hand your null object in tMap with ternary operator?

Best regards

Sabrina

Anonymous
Not applicable
Author

The problem is I want to set the database column value to null. Setting it to 0 is not ok, because there are missing values and there are zero values. Setting it to some arbitrarily large negative value has the same problem. I need to know that I don't know.

Anonymous
Not applicable
Author

Turns out the way to handle this is to set the value to

net.sf.json.JSONNull.getInstance()

tWriteJson will set it correctly as a JSON null then.