DEV Community

Pedro Pimienta M.
Pedro Pimienta M.

Posted on

JSON and scehama validator libraries for Node

Hi, I'm a new into the Node world, but I'm working in a project where are using a library called Joi for to validate the JSON data came from the request and other things. Then, i decided to search other library, and I found several, than I decided to choose some and create this post, my first post in this community.

Yup

GitHub logo jquense / yup

Dead simple Object schema validation

Yup

Yup is a schema builder for runtime value parsing and validation. Define a schema, transform a value to match, assert the shape of an existing value, or both. Yup schema are extremely expressive and allow modeling complex, interdependent validations, or value transformation.

You are viewing docs for the v1.0.0 of yup, pre-v1 docs are available: here

Killer Features:

  • Concise yet expressive schema interface, equipped to model simple to complex data models
  • Powerful TypeScript support. Infer static types from schema, or ensure schema correctly implement a type
  • Built-in async validation support. Model server-side and client-side validation equally well
  • Extensible: add your own type-safe methods and schema
  • Rich error details, make debugging a breeze

Getting Started

Schema are comprised of parsing actions (transforms) as well as assertions (tests) about the input value Validate an input value to parse it and run the configured set of assertions. Chain together methods to…

Yup is a JavaScript schema builder for value parsing and validation. Define a schema, transform a value to match, validate the shape of an existing value, or both. Yup schema are extremely expressive and allow modeling complex, interdependent validations, or value transformations.

Yup's API is heavily inspired by Joi, but leaner and built with client-side validation as its primary use-case. Yup separates the parsing and validating functions into separate steps. cast() transforms data while validate checks that the input is the correct shape. Each can be performed together (such as HTML form validation) or seperately (such as deserializing trusted data from
APIs).

ajv

GitHub logo ajv-validator / ajv

The fastest JSON schema Validator. Supports JSON Schema draft-04/06/07/2019-09/2020-12 and JSON Type Definition (RFC8927)

Ajv logo

 

Ajv JSON schema validator

The fastest JSON validator for Node.js and browser.

Supports JSON Schema draft-04/06/07/2019-09/2020-12 (draft-04 support requires ajv-draft-04 package) and JSON Type Definition RFC8927.

build npm npm downloads Coverage Status SimpleX Gitter GitHub Sponsors

Ajv sponsors

Mozilla

Microsoft

RetoolTideliftSimpleX

Contributing

More than 100 people contributed to Ajv, and we would love to have you join the development. We welcome implementing new features that will benefit many users and ideas to improve our documentation.

Please review Contributing guidelines and Code components.

Documentation

All documentation is available on the Ajv website.

Some useful site links:

Since I asked to support Ajv development 40 people and 6 organizations contributed via GitHub and OpenCollective - this support helped receiving the MOSS grant!

Your continuing support is very important - the funds will be used…

Superstructure

GitHub logo ianstormtaylor / superstruct

A simple and composable way to validate data in JavaScript (and TypeScript).

A simple and composable way
to validate data in JavaScript (and TypeScript)

UsageWhy?PrinciplesDemoExamplesDocumentation

Superstruct makes it easy to define interfaces and then validate JavaScript data against them. Its type annotation API was inspired by Typescript, Flow, Go, and GraphQL, giving it a familiar and easy to understand API.

But Superstruct is designed for validating data at runtime, so it throws (or returns) detailed runtime errors for you or your end users. This is especially useful in situations like accepting arbitrary input in a REST or GraphQL API. But it can even be used to validate internal data structures at runtime when needed.

Usage

Superstruct allows you to define the shape of data you want to validate:

import { assert, object, number, string, array } from 'superstruct'
const Article = object({
Enter fullscreen mode Exit fullscreen mode

Superstruct makes it easy to define interfaces and then validate JavaScript data against them. Its type annotation API was inspired by Typescript, Flow, Go, and GraphQL, giving it a familiar and easy to understand API.

But Superstruct is designed for validating data at runtime, so it throws (or returns) detailed runtime errors for you or your end users. This is especially useful in situations like accepting arbitrary input in a REST or GraphQL API. But it can even be used to validate internal data structures at runtime when needed.

Forg Js

GitHub logo oussamahamdaoui / forgJs

ForgJs is a javascript lightweight object validator.

forgJs logo

ForgJs is a JavaScript lightweight object validator. Go check the Quick start section and start coding with love ❤️

email

password

number

url

See more live examples here

Quick start

Install it via npm by running npm i @cesium133/forgjs

Your first validator

  const { Validator, Rule } = require('@cesium133/forgjs');
const emailRule = new Rule({
    type: 'email',
    user: user => user === 'dedede',
    domain: domain => ['outlook', 'gmail', 'yahoo'].indexOf(domain) !== -1,
}, null);

const passwordRule = new Rule({
    type: 'password',
    minLength: 8,
    uppercase: 1,
    numbers: 1,
    matchesOneOf: ['@', '_', '-', '.', '!'],
}, null);

const vComplex = new Validator({
    age: new Rule({ type
Enter fullscreen mode Exit fullscreen mode

Top comments (0)