New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More β†’
Socket
Sign inDemoInstall
Socket

json-schema-library

Package Overview
Dependencies
Maintainers
2
Versions
94
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-schema-library

Customizable and hackable json-validator and json-schema utilities for traversal, data generation and validation

  • 9.0.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created

What is json-schema-library?

The json-schema-library is a JavaScript library for working with JSON Schema. It provides tools for validating JSON data against a schema, resolving references, and managing schema dependencies.

What are json-schema-library's main functionalities?

Schema Validation

This feature allows you to validate JSON data against a defined schema. The code sample demonstrates how to validate an object with properties 'name' and 'age' against a schema that requires these properties to be of specific types.

const { validate } = require('json-schema-library');

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

const data = { name: 'John', age: 30 };

const result = validate(data, schema);
console.log(result.valid); // true

Reference Resolution

This feature resolves JSON Schema references within a schema. The code sample shows how to resolve a reference to a 'person' definition within a schema.

const { resolveRefs } = require('json-schema-library');

const schema = {
  definitions: {
    person: {
      type: 'object',
      properties: {
        name: { type: 'string' }
      }
    }
  },
  $ref: '#/definitions/person'
};

const resolvedSchema = resolveRefs(schema);
console.log(resolvedSchema);

Schema Compilation

This feature compiles a JSON Schema into a more efficient format for validation. The code sample demonstrates compiling a schema that includes an 'email' property with a specific format.

const { compile } = require('json-schema-library');

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

const compiledSchema = compile(schema);
console.log(compiledSchema);

Other packages similar to json-schema-library

Keywords

FAQs

Package last updated on 15 Aug 2023

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