- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
How to check if JSON content is null (or empty)?
- Labels:
-
Apache NiFi
Created ‎08-07-2019 08:26 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
HI All,
does anybody know how to check if the content of the file is null or empty? (JSON for example)?
Thanks,
Nera
Created ‎08-07-2019 08:46 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Created on ‎08-07-2019 08:49 AM - edited ‎08-17-2019 04:18 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@ 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.
Created ‎08-07-2019 08:55 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@Rosa Negra
In this case I would use RouteOnContent to check null and maybe additionally check filesize to be on the safe side.
Created on ‎08-07-2019 09:06 AM - edited ‎08-17-2019 04:17 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@Justen Thanks!
Created on ‎08-07-2019 09:05 AM - edited ‎08-17-2019 04:17 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Created ‎08-07-2019 06:53 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.
Created on ‎08-17-2020 12:10 AM - edited ‎08-17-2020 03:30 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
