Socket
Socket
Sign inDemoInstall

ajv-draft-04

Package Overview
Dependencies
6
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

ajv-draft-04

Ajv class for JSON Schema draft-04


Version published
Maintainers
1
Weekly downloads
1,536,740
decreased by-8.47%

Weekly downloads

Package description

What is ajv-draft-04?

The ajv-draft-04 package is an extension for AJV, a popular JSON schema validator, enabling it to validate schemas written according to the JSON Schema Draft 04 specification. This package allows users to leverage AJV's fast validation capabilities while ensuring compatibility with older schema versions.

What are ajv-draft-04's main functionalities?

Validating JSON objects against a Draft 04 schema

This code demonstrates how to create a new AJV instance compatible with Draft 04 schemas, compile a schema, and validate a JSON object against it. It checks if the object meets the schema requirements (in this case, having a name as a string and an age as a number not less than 18), and prints whether the object is valid or not.

{"const Ajv = require('ajv-draft-04'); const ajv = new Ajv(); const schema = { 'type': 'object', 'properties': { 'name': { 'type': 'string' }, 'age': { 'type': 'number', 'minimum': 18 } }, 'required': ['name', 'age'] }; const validate = ajv.compile(schema); const valid = validate({ 'name': 'John Doe', 'age': 25 }); if (valid) console.log('Valid!'); else console.log('Invalid: ' + ajv.errorsText(validate.errors));"}

Other packages similar to ajv-draft-04

Readme

Source

ajv-draft-04

Ajv with JSON Schema draft-04 support

build npm coverage Gitter GitHub Sponsors

Usage

You need to install both ajv and this package (to allow upgrading ajv without upgrading this package):

npm i ajv ajv-draft-04
// ESM/TypeScript import
import Ajv from "ajv-draft-04"
// Node.js require:
const Ajv = require("ajv-draft-04")

const ajv = new Ajv()

See ajv site for documentation.

Tests

npm install
git submodule update --init
npm test

License

MIT

Keywords

FAQs

Last updated on 23 May 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc