Declarative and portable
Rules are plain data. Store them as JSON and share one schema between the backend, the frontend and services written in other languages.
Describe valid data once, as a declarative schema. Get the same validation, the same output and the same error codes in JavaScript, Perl, PHP, Python, Go, Erlang and more.
{
name: 'required',
email: ['required', 'email'],
age: ['positive_integer', { min_number: 18 }],
address: { nested_object: {
city: 'required',
zip: 'positive_integer'
}}
}{
email: 'john@', age: 16, role: 'admin',
address: { city: 'Kyiv', zip: 'O1001' }
}{
"name": "REQUIRED",
"email": "WRONG_EMAIL",
"age": "TOO_LOW",
"address": {
"zip": "NOT_POSITIVE_INTEGER"
}
}Edit the rules or the input. The result is computed live in your browser by the JavaScript implementation, and every other implementation returns exactly the same.
{
"name": "John",
"email": "john@example.com",
"gender": "male",
"password": "mypassword1",
"password2": "mypassword1"
}One specification and one shared test suite, many languages.