Check JSON for empty values

Eight Stars

Check JSON for empty values

How can I validate if the JSON object is not empty? Currently, I am processing the data[] array and it is inserting values in DB. If its a blank, then, it inserts a NULL. How can I achieve this? 

 

Correct JSON:

{
	"RESULT_1": {
		"data": [
			["0", null, "12345", "other"],
			["1", "a", "54321", "MA"],
			["0", null, "76543", "RI"]
		]
	}
}

Empty JSON:

 

{
	"RESULT_1": {
		"data": [		]
	}
}

 

 Thanks!

Moderator

Re: Check JSON for empty values

Hello,

Have you tried to replace your empty/null field with "Null" string?

Such as:

output_row.output = input_row.output.replaceAll(",\"[a-zA-Z][a-zA-Z]*\":\\[\\]", "Null"); in tJavaRow.

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.
Eight Stars

Re: Check JSON for empty values

@xdshi:
Thanks for your reply. So, this will essentially check [] and if it does not contain anything, mark it null?

Moderator

Re: Check JSON for empty values

Hello,

It will check empty values in your JSON file.

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.
Eight Stars

Re: Check JSON for empty values

Thank you!

What’s New for Talend Spring ’19

Watch the recorded webinar!

Watch Now

Definitive Guide to Data Quality

Create systems and workflow to manage clean data ingestion and data transformation.

Download

Tutorial

Introduction to Talend Open Studio for Data Integration.

Watch

Downloads and Trials

Test drive Talend's enterprise products.

Downloads