February 2013 Archives

Introducing Sah, another data validation framework

This blog post introduces Sah, my data validation framework (or data validation language and validator generator, to be more exact). The very first work on Sah began almost 4 years ago as Data::Schema. The name change to Sah and the first release of Data::Sah happened in late 2011.

To validate data, first you write a Sah schema. Sah schemas are also data structures and are very much similar to JSON schemas, except that they are more featureful and (at least to to me) more convenient to write.

The design and implementation principle are mostly laziness and DRY:

  • I want concise syntax for common things; I don't want to have to type a lot especially if they are mostly the same things;
  • I want to use it for everything, from validating function arguments to web requests; I don't want to have to use two different validation languages (e.g. one for function arguments, another for class attributes, another for JSON data);
  • I want to generate JavaScript client-side validation code from the schema; I dont' want to have to write JavaScript code manually;
  • If someday there needs to be server-side validation performed in languages other than Perl, I want to generate that code too instead of having to write them manually;
  • I want good default error message, most of the time I don't want to have to write error messages manually;
  • I want translation of error messages;

About Steven Haryanto

user-pic A programmer (mostly Perl 5 nowadays). My CPAN ID: SHARYANTO. I'm sedusedan on perlmonks. My twitter is stevenharyanto (but I don't tweet much). Follow me on github: sharyanto.