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 🙏

© 2026 – Pkg Stats / Ryan Hefner

the-json-library

v1.1.0

Published

A lightweight validation library, which validates JSON data against a JSON schema.

Downloads

5

Readme

The JSON Library

A lightweight JSON schema validation library for JavaScript that can be used in both browser and Node.js environments.

Features

  • Validate JSON data against schemas
  • No external dependencies
  • Works in both browser and Node.js
  • Supports common validation types and formats
  • Comprehensive error reporting
  • Small footprint
  • Strict validation with additional properties control

Installation

npm install the-json-library

Usage

Basic Usage

import { validate } from 'the-json-library';

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

// Validate some data
const data = {
  name: 'John Doe',
  email: '[email protected]',
  age: 30
};

const result = validate(data);

if (result.isValid) {
  console.log('Validation successful!');
} else {
  console.error('Validation errors:', result.errors);
}

Static Validation

You can also use the static method without creating an instance:

import { validate } from 'the-json-library';

const result = validate(data, schema);

if (result.isValid) {
  console.log('Validation successful!');
} else {
  console.error('Validation errors:', result.errors);
}

Additional Properties Control

By default, the library rejects any properties not defined in the schema:

// Schema only defines name and email
const schema = {
  type: 'object',
  properties: {
    name: { type: 'string' },
    email: { type: 'string' }
  }
};

// Data contains an extra property 'age'
const data = {
  name: 'John Doe',
  email: '[email protected]',
  age: 30  // This will cause validation failure
};

const result = validate(data, schema);
// result.isValid will be false
// result.errors will contain an error about 'age' being an additional property

To allow additional properties, set additionalProperties to true:

const schema = {
  type: 'object',
  properties: {
    name: { type: 'string' },
    email: { type: 'string' }
  },
  additionalProperties: true  // Allow any additional properties
};

// Now this will pass validation
const data = {
  name: 'John Doe',
  email: '[email protected]',
  age: 30  // This is now allowed
};

You can also provide a schema for additional properties:

const schema = {
  type: 'object',
  properties: {
    name: { type: 'string' },
    email: { type: 'string' }
  },
  // All additional properties must be numbers
  additionalProperties: { type: 'number' }
};

// This will pass validation
const data = {
  name: 'John Doe',
  email: '[email protected]',
  age: 30,  // Valid additional property (number)
  score: 95  // Valid additional property (number)
};

Validation Result

The validation result contains:

  • isValid - boolean indicating if the validation passed
  • errors - array of error objects with:
    • path - the path to the property that failed validation
    • message - description of the error

Supported Schema Features

Types

  • string
  • number
  • integer
  • boolean
  • array
  • object
  • null

String Validations

  • minLength / maxLength - string length constraints
  • pattern - regular expression pattern
  • format - predefined formats (email, date, date-time, uri)

Number Validations

  • minimum / maximum - value constraints

Object Validations

  • properties - schema for each property
  • required - list of required properties
  • additionalProperties - controls whether properties not defined in the schema are allowed

Array Validations

  • items - schema for array items

Other Validations

  • enum - list of allowed values

Schema Format

Schemas should follow a simplified JSON Schema format. Here's an example of a more complex schema:

{
  "type": "object",
  "required": ["id", "name", "metadata"],
  "properties": {
    "id": { "type": "integer" },
    "name": { "type": "string", "minLength": 1 },
    "email": { "type": "string", "format": "email" },
    "tags": {
      "type": "array",
      "items": { "type": "string" }
    },
    "metadata": {
      "type": "object",
      "properties": {
        "created": { "type": "string", "format": "date-time" },
        "status": { "enum": ["active", "inactive", "pending"] }
      },
      "additionalProperties": false
    }
  },
  "additionalProperties": false  // No additional root properties allowed
}

License

MIT