Seven 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!

4 REPLIES
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.
Seven 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.
Seven Stars

Re: Check JSON for empty values

Thank you!