Your First Validation, The Easy Way
CsvPath is a very flexible language. There is often another way to do a thing. Sometimes you can make your work simpler than you first thought.
CsvPath is a rules-based validation language. Rules that define when data is valid are powerful. A rule can do things that a structural approach can't do. But sometimes just clarifying the shape of the data is enough. You can read more about the difference between these approaches here.
Here's our First Validation example again, this time using structure to define what is valid.
Here we're using line() to specify what a line of data looks like in a valid CSV or Excel file. We expect exactly three headers and require two of them to always have values.
We also added some metadata and a mode configuration. The id
field will become the csvpath's identity
, available on the CsvPath
instance's identity
property. It will be used in built-in validation errors. The description
is ours to use as we wish—it is a user-defined field. And the validation-mode
is a setting that tells the CsvPath
instance that we want to print errors, but not raise exceptions, and we want the file to be marked as invalid if there are errors. We sometimes call this failing the file.
There's a lot more you could do, of course. This is barely the tip of the iceburg.
Last updated