JSON validating libraries for promise chains

published Jan 31, 2016 02:25   by admin ( last modified Jan 31, 2016 02:34 )

I'm looking at ways of marshalling/validating what gets transported through a javascript promise chain. I first looked at  Typescript, but after a tip from a friend now looking at JSON schema validators and similar. These are the ones I'm looking at right now:

bugventure/jsen: JSON-Schema validator built for speed

A custom format validator can be specified as:

  • a regular expression string
  • a regular expression object
  • a function (value, schema) that must return a truthy value if validation passes

epoberezkin/ajv: The fastest JSON schema Validator

.addFormat(String name, String|RegExp|Function|Object format)

Add custom format to validate strings. It can also be used to replace pre-defined formats for ajv instance.

Strings are converted to RegExp.

Function should return validation result as true or false.

exjs/exmodel: Extensible data model - high performance data processing, schema builder, validator, and sanitizer.

Lots of built-in types and also has regex. No custom types.

pandastrike/jsck

No regular expressions, no custom types afaict.

The above ones are selected a bit for speed, but I will focus on the ones that are most flexible with custom types, allowing both regular expressiosn and functions as validators, and which ones have a nice syntax. Remains to be evaluated.