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

@bpmn-io/json-schema-validator

Package Overview
Dependencies
Maintainers
6
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bpmn-io/json-schema-validator

Validate JSON based on JSON Schema files

  • 0.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
6
Weekly downloads
 
Created
Source

json-schema-validator

CI

Validate JSON based on JSON Schema files.

Installation

$ npm i --save @bpmn-io/json-schema-validator

Usage

Given

import { Validator } from '@bpmn-io/json-schema-validator';

import schema from './test/fixtures/json-schema/schema.json';

import sample from './test/fixtures/samples/invalid-name.json';

const validator = new Validator({
  schema: schema
});

const {
  valid,
  errors
} = validator.validate(sample);

if (!valid) {
  console.error('Invalid JSON detected:', errors);
}

This will print detailed information about errors inside the sample

[
  {
    "message": "must start with <number_>",
    "keyword": "errorMessage",
    "dataPath": "/properties/0/name",
    "schemaPath": "#/properties/properties/items/allOf/0/then/properties/name/errorMessage",
    "params": {
      "rawErrors": [
        {
          "keyword": "pattern",
          "dataPath": "/properties/0/name",
          "schemaPath": "#/properties/properties/items/allOf/0/then/properties/name/pattern",
          "params": {
            "pattern": "^(number_)"
          },
          "message": "should match pattern \"^(number_)\""
        }
      ]
    }
  }
]

It's also possible to validate multiple objects at once

import Validator from '@bpmn-io/json-schema-validator';

import schema from './test/fixtures/json-schema/schema.json';

import samples from './test/fixtures/samples/multiple-samples.json';

const validator = new Validator({
  schema: schema
});

const {
  valid,
  results
} = validator.validateAll(samples);

if (!valid) {
  console.error('Invalid JSON objects detected:', results.filter(r => !r.valid));
}

Example JSON Schemas

License

MIT

Keywords

FAQs

Package last updated on 25 Mar 2021

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