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

json-schema-specificity

v2.0.0

Published

A JavaScript library for comparing JSON Schema specificity

Readme

json-schema-specificity

A JavaScript library for comparing JSON Schema specificity and extending schemas. This library helps determine if one JSON schema is more specific than another, meaning that any JSON document that would be validated by the extension schema would also be validated by the original schema. It also provides functionality to extend schemas by merging them.

Live Demo

Try out the library with our interactive demo. The demo allows you to input two JSON schemas and instantly see if one is more specific than the other.

Installation

npm install json-schema-specificity

Usage

import { isMoreSpecific, extendSchema } from 'json-schema-specificity';

// Check if one schema is more specific than another
const original = {
  type: 'object',
  properties: {
    name: { type: 'string' }
  }
};

const extension = {
  type: 'object',
  properties: {
    name: { type: 'string', minLength: 1 }
  }
};

const isMoreSpecificResult = isMoreSpecific(original, extension);
// result: true (because extension is more specific than original)

// Extend a schema with another
const base = {
  type: 'object',
  properties: {
    user: {
      type: 'object',
      properties: {
        name: { type: 'string' }
      }
    }
  }
};

const delta = {
  properties: {
    user: {
      properties: {
        age: { type: 'number' }
      }
    }
  }
};

const extended = extendSchema(base, delta);
// result: {
//   type: 'object',
//   properties: {
//     user: {
//       type: 'object',
//       properties: {
//         name: { type: 'string' },
//         age: { type: 'number' }
//       }
//     }
//   }
// }

API

isMoreSpecific(original, extension)

Determines if the extension schema is more specific than the original schema.

Parameters

  • original (Object): The original JSON schema
  • extension (Object): The extension JSON schema to compare

Returns

  • boolean: Returns true if the extension schema is more specific than the original schema, false otherwise.

extendSchema(base, extension)

Recursively merges two JSON schemas, with the extension schema overriding or extending the base schema.

Parameters

  • base (Object): The base JSON schema
  • extension (Object): The extension JSON schema to merge with the base

Returns

  • Object: A new object representing the merged schema

Features

  • Supports JSON Schema Draft-07
  • Handles various schema keywords:
    • Type compatibility (including number/integer relationships)
    • Required properties
    • Property constraints
    • Numeric constraints (minimum, maximum, multipleOf)
    • String constraints (minLength, maxLength, pattern)
    • Array constraints (minItems, maxItems, uniqueItems)
    • Enum values
    • Const values
    • Additional properties
  • Schema extension capabilities:
    • Deep merging of nested objects
    • Array handling
    • Primitive value overrides
    • Null/undefined handling

Examples

Type Compatibility

isMoreSpecific(
  { type: 'number' },
  { type: 'integer' }
); // true

Numeric Constraints

isMoreSpecific(
  { type: 'number', minimum: 0, maximum: 100 },
  { type: 'number', minimum: 10, maximum: 50 }
); // true

Array Constraints

isMoreSpecific(
  { type: 'array', items: { type: 'string' }, maxItems: 5 },
  { type: 'array', items: { type: 'string' }, minItems: 1, maxItems: 3 }
); // true

Schema Extension

extendSchema(
  { type: 'object', required: ['name'] },
  { additionalProperties: false }
); // { type: 'object', required: ['name'], additionalProperties: false }

License

ISC

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.