Skip to content
forked from nuxodin/jema.js

JSON Schema handling / validator

License

Notifications You must be signed in to change notification settings

zaxbowow/jema.js

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jema.js

JSON Schema validator for deno and browsers

| JSON Schema is the leading standard for validating and describing data. It is platform-independent and simplifies the automation of validation, documentation, and processing of data.

Features

🚀 Performant
🕊️ Lightweight (< 4kb brotli)
🤝 Works in the Browser and deno (no node.js at the moment)
📦 No dependencies
🆗 JSONSchema draft-2020-12 (only this)

Basic ussage

const schema = new Schema({
    type: 'string',
    minLength: 3,
    pattern: '^[a-zA-Z]+$',
});
await schema.deref(); // Dereference remote schemas

schema.validate('Li') // false
schema.validate('Liam') // true
schema.validate('Li-Am') // false

Install

import {Schema} from 'https://cdn.jsdelivr.net/gh/nuxodin/[email protected]/schema.min.js';

Debugging

// errors
const errors = schema.errors('L-')
for (const error of errors) {
    console.log(error.message)
    // "L-" does not match minLength:3
    // "L-" does not match pattern:^[a-zA-Z]+$
}

// schema validation
const schema = new Schema({
    type: 'stringg',
});
await schema.schemaErrors(); 

Todo

  • Better error messages (with schema location, conforming to the JSON Schema spec)
  • Fix a few bugs in the test suite: link mainly
    • "$dynamicRef"
    • "$vocabulary"
    • and some minor "format" errors

If someone wants to help, please do so.

About

  • MIT License, Copyright (c) 2022 (like all repositories in this organization)
  • Suggestions, ideas, finding bugs and making pull requests make us very happy. ♥

About

JSON Schema handling / validator

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 69.4%
  • HTML 30.6%