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

@ferrow/json-schema-from-sample

v1.0.0

Published

Infer a draft-07 JSON Schema subset from sample JSON data — types, nested structures, nullable/required/enum inference across multiple samples, format detection. Zero runtime dependencies.

Downloads

29

Readme

json-schema-from-sample

CI

Infer a draft-07 JSON Schema subset from sample JSON data. Strict TypeScript, zero runtime dependencies.

Why

Hand-writing JSON Schema for an API response or config shape is tedious and drifts from reality. This library infers one from real samples — the more samples you provide, the more it can safely say about nullability, required fields, and enums, and it never claims more than the samples support.

Quickstart

import { infer } from "json-schema-from-sample";

const schema = infer([
  { id: "8f14e45f-ceea-467e-b3a3-7a3d3f2f1a10", email: "[email protected]", role: "admin" },
  { id: "9a14e45f-ceea-467e-b3a3-7a3d3f2f1a11", email: "[email protected]", role: "member" },
  // ...
]);

API

infer(samples, options?): RootSchema

Merges observations across all samples into a single schema.

  • options.tupleLengthConstraints (default false) — emit minItems/maxItems when an array field's observed length never varies. Off by default: a few samples can't prove a length rule.
  • options.enumMaxDistinct (default 5) — max distinct string values for enum detection.
  • options.enumMinSamples (default 10) — min sample count before enum detection runs.

Inference rules

  • Types: merged as a union across samples (e.g. ["null", "string"]); integer + float observed together widen to "number".
  • Nullable: a field observed as null in some samples and a value in others gets "null" added to its type.
  • Required: a property present in every sample that reached that object is marked required.
  • Enum: string fields with ≤enumMaxDistinct distinct values across ≥enumMinSamples samples.
  • Format: date-time, email, uuid, uri detected via regex when all observed strings at that field match.
  • Arrays: item schema is inferred by merging every element across every array observed at that path.

Limits

  • Samples-only inference — it cannot prove constraints samples don't demonstrate (numeric ranges, string length bounds, exact tuple shapes). tupleLengthConstraints is opt-in for that reason.
  • Format detection requires unanimous agreement across all observed strings at a field; mixed-format fields get no format.
  • No $ref, oneOf/anyOf, or schema composition beyond simple type unions — this targets the common 80% case, not the full draft-07 spec.

Part of the ferrow-toolkit collection · Sponsored by Ferrow