Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@cfworker/json-schema

Package Overview
Dependencies
Maintainers
0
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cfworker/json-schema

A JSON schema validator that will run on Cloudflare workers. Supports drafts 4, 7, 2019-09, and 2020-12.

  • 4.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
158K
increased by35.28%
Maintainers
0
Weekly downloads
 
Created

What is @cfworker/json-schema?

@cfworker/json-schema is a lightweight and fast JSON schema validator and parser that is designed to work in both Node.js and browser environments. It is part of the Cloudflare Workers suite of tools, which are optimized for performance and efficiency.

What are @cfworker/json-schema's main functionalities?

Schema Validation

This feature allows you to validate JSON data against a defined schema. The code sample demonstrates creating a schema for an object with 'name' and 'age' properties, and then validating a data object against this schema.

const { Validator } = require('@cfworker/json-schema');

const schema = {
  type: 'object',
  properties: {
    name: { type: 'string' },
    age: { type: 'integer', minimum: 0 }
  },
  required: ['name', 'age']
};

const validator = new Validator(schema);
const data = { name: 'John Doe', age: 30 };
const result = validator.validate(data);

console.log(result.valid); // true
console.log(result.errors); // []

Schema Compilation

This feature allows you to compile a JSON schema into a validation function. The code sample shows how to compile a schema and use the resulting function to validate data.

const { compile } = require('@cfworker/json-schema');

const schema = {
  type: 'object',
  properties: {
    email: { type: 'string', format: 'email' }
  },
  required: ['email']
};

const validate = compile(schema);
const data = { email: 'test@example.com' };
const valid = validate(data);

console.log(valid); // true

Other packages similar to @cfworker/json-schema

Keywords

FAQs

Package last updated on 06 Jan 2025

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc