Skip to content

πŸ‹β€πŸŸ© Just enough JavaScript object validation

License

Notifications You must be signed in to change notification settings

dbushell/jsonlike

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ‹β€πŸŸ© jsonlike

JSR NPM

Just enough JavaScript object validation.

jsonlike is a tiny < 1kB library used to validate JavaScript objects against a JSON-like schema.

It can:

  • Match properties by primitive types
  • Match arrays of single type values
  • Match nested objects

Usage

import {jsonlike} from '@dbushell/jsonlike';

const json = JSON.parse(`{
  "greeting": "Hello, World!",
  "items": [{"id": 1}, {"id": 2}, {"id": 3}]
}`);

const valid = jsonlike(json, {
  greeting: 'string',
  items: [{id: 'number'}]
});

Notes

Use Ajv or Zod for full schema validation.


MIT License | Copyright Β© 2024 David Bushell

About

πŸ‹β€πŸŸ© Just enough JavaScript object validation

Topics

Resources

License

Stars

Watchers

Forks