npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

json-schema-remote

v1.6.2

Published

Node.js module to validate JSON objects against a JSON Schema, including remote references ($ref)

Downloads

721

Readme

NPM version Dependency Status Downloads

Node.js module to validate JSON objects against a JSON Schema, including remote references ($ref).

Features

Uses tv4 for validation, but asynchronously loads missing remote schemas automatically. Just input a JSON Schema or a URI to a JSON Schema, and it will do the rest. No more manual loading of remote schemas!

Install

$ npm install --save json-schema-remote

Usage

The module can be used from a Node.js script, or directly on command line.

Module usage

Node.js ≥ 4.0.0 is required.

const validator = require('json-schema-remote');

validator.validate(data, schema)
.then(() => {
  // data is valid!
})
.catch((error) => {
  // handle error
});

Optionally, a callback can be provided as third parameter. It will be called with (error, isValid).

Command line usage

# when installed globally
json-schema-remote dataURL schemaURL
# when installed locally
./bin/json-schema-remote.js dataURL schemaURL

API

validator.validate(data, schema[, callback])

Validate a JSON against a JSON Schema.

  • data is either a JSON object or the URL to a JSON object.

  • schema is either a valid JSON schema or the URL to a valid JSON schema.

  • callback (optional) is called when validation is finished. Signature:

    callback(error, isValid)

    • error will contain validation errors (error.errors) or be null if validation succeeded.
    • isValid is true when validation succeeded, or false otherwise.

If no callback is provided, the function returns a Promise.

validator.preload([url, ]schema)

Preload a JSON Schema so it will not be necessary to remotely load it when validating. Synchronous function.

  • url can be the id of the schema. May be omitted if schema contains the id property. Otherwise, it will overwrite it.
  • schema the Schema to add as JSON

Calls tv4.addSchema internally.

validator.getSchema(url)

Get a JSON Schema from tv4 cache.

  • url URL/ID of the JSON Schema

Calls tv4.getSchema internally.

validator.setLoggingFunction(fn)

Set a custom Logging function. Will take console.log else. It is logged when data is loaded over the network. Throws an error if fn is no function.

Tests

mocha

Note that the tests need internet access for testing download of remote schemas.

Changelog

1.5.1

  • adds new webpack build

1.5.0

  • patchday with new version of validator

1.3.7

  • readd meta schema on dropSchemas

1.3.6

  • use packaged schema for metaSchema validation, should fix Mixed-Content warnings

1.3.5

  • adds dropSchema to type definitions

1.3.4

  • add option to remove all schemas from cache

1.3.3

  • allow string only "jsons"
  • improved require_tld logic in requests

1.3.2

  • fixed infinity loop when schema has broken refs

1.3.1

  • add request cache

1.3.0

  • adds typescript typings

1.2.5 / 1.2.6

  • fixed bufferhandling in browser with superagent

1.2.1

  • updated Dependencies, fixed Tests for Chai 4

1.2.0

  • adds getSchema(url)

1.1.6

  • version 3.0.0 tv4-formats with fixed typescript usage

1.1.4 - 1.1.5

  • bugfixes

1.1.3

  • removed lodash
  • split shell usage into single file

1.1.2

  • updated dependencies

1.1.1

  • made the feature from 1.1.0 actually work

1.1.0

  • added function setLoggingFunction(fn) to add a custom logger function instead of console.log

1.0.0

  • breaking change: Node.js >= 4.0.0 is required due to the usage of Promises and Arrow functions. Use [email protected] for older node versions.
  • added support for Promises (callbacks still work, too)
  • removed dependency on async
  • updated dependencies

0.1.7

  • removed deprecation caused by validator.js

0.1.6

  • updated dependencies

0.1.5

  • updated dependencies

0.1.4

  • updated dependencies
  • added mocha and mocha-bamboo-reporter to dev dependencies

0.1.3

  • updated dependencies

0.1.2

  • updated dependencies

0.1.1

  • updated dependencies
  • updated tests for chai 2.x
  • updated test for remote schema and data

0.1.0

  • added preload function

0.0.2

  • fix for package.json file

0.0.1

  • initial release

License

MIT © entrecode GmbH