How do we check if NO DATA in a CSV file after filtering out headers

Hello, I need to check if there is no actual data after reading and parsing a CSV file, I am using the CSV Parser and have checked the ‘Contains Header’ (as we will always have a row with headers), I then follow it with a Mapper. If we have no data at this point we need to stop processing and go down a different route. I’m struggling with how after the Mapper, I check if no data is present in my document ($). We have a router snap next and have tried the following options, but none seem to work in the expression window:-

$ == null

Any help appreciated.

Hi @MikeP,

After the CSV parser, are your headers with empty values like "" ? Or simply there’s no data after after the csv parser ?

hi j.evegelvski, the files will always have header text values like “Emp_ID”, the rows after this will be empty. I cant identify if we have any data for this file situation - no data. My dev head is saying maybe a ‘row count’ property (if data in any rows) after header row filtered out, this would be handy, but doesn’t seem to exist. Then just check if this value > 0.

Addendum: After the CSV Parser snap, then the next snap is a straight mapper snap for the document ($) the output view is

Hence why I thought the expressions I mentioned initially would work.

Hi @MikeP,

In that case your expression should work because $.isEmpty() should return true. Not sure why it doesn’t work for you, but you can also try with the following: $.values().length == 0. Can you also share your settings in the router snap ?

hi j.evegelvski, sorry for delayed reply.

I think I sussed it now.

!$.isEmpty() although no errors syntactically on setting it in the expression validation, it doesn’t seem to functionally work.

However, $.isEmpty() == false, the more explicit syntax, does work, therefore the router flow now conforms as expected.

Thanks for your assistance!


Glad that it is working now. But the reason why !$.isEmpty() doesn’t work it’s because:

  • When the input is empty - {}, the expression !$.isEmpty() will return false because you are checking first if the input is empty ( which is true ) but you are making it false ( with the ! sign ) and in the end the Router won’t output anything. It’s essentially like saying "Check if input is empty, and if it is, stop the flow of the data ( which in this case it should continue to another output instead of stopping )."
  • You can also solve this with the following Router settings

    The first expression will return true if the input data is not empty ( it will output the input data to the first output view ), and the second expression will simply return true and will output the data on the second output view. With the First match option checked, only the first expression that returns true will be evaluated to the output even if there are more expressions that return true.

Smashing thanks for the additional information, good knowledge to know.