Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

How to check if JSON content is null (or empty)?

avatar
Explorer

HI All,

does anybody know how to check if the content of the file is null or empty? (JSON for example)?


Thanks,

Nera

7 REPLIES 7

avatar
Master Collaborator

Hi @Rosa Negra

I only have experience concerning JSON.

In my opinion it depends what the content looks like.

If the content of an empty JSON is [ ] the flowfile disappears when I do a SplitJson with JsonPath Expression value $.

If the content looks like this [ { } ] I check with RouteOnContent on this (^\[\{\}\]) and filter the file out.

avatar
Explorer

@ Justen my JSON file is being converted to null (file size iz 4bytes) after wrong JOLT is applied.

So, when I open the JSON it's litterally 'null'. There are no brackets.. just null. 110204-1565167770957.png

avatar
Master Collaborator

@Rosa Negra
In this case I would use RouteOnContent to check null and maybe additionally check filesize to be on the safe side.

avatar
Explorer

@Justen Thanks!110230-1565168780528.png

avatar
Explorer

@ Justen i believe this is the answer:


110205-1565168722104.png


Thanks!

avatar

The above question and the entire response thread below were originally posted in the Community Help track. On Wed Aug 7 18:53 UTC 2019, a member of the HCC moderation staff moved it to the Data Ingestion & Streaming track. The Community Help Track is intended for questions about using the HCC site itself.

Bill Brooks, Community Moderator
Was your question answered? Make sure to mark the answer as the accepted solution.
If you find a reply useful, say thanks by clicking on the thumbs up button.

avatar

To check null in JavaScript, use triple equals operator(===) or Object is() method. If you want to use Object.is() method then you two arguments.

 

1)  Pass your variable value with a null value.

2) The null value itself.

 

To find the difference between null and undefined, use the triple equality operator or Object is() method.

 

To loosely check if the variable is null, use a double equality operator(==). The double equality operator can not tell the difference between null and undefined, so it counts as same. So if you want to strict check, then don't use a double equality operator. It will lead to misconclusion.