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

jssb-cli

v1.0.1

Published

A TypeScript library and CLI tool to generate JSON schemas from sample JSON data

Downloads

19

Readme

JSON Schema Builder

A TypeScript library and CLI tool to generate JSON schemas from sample JSON data. Supports complex nested objects, arrays, and automatic format detection.

Installation

Global Installation (CLI)

npm install -g jssb-cli

Local Installation (Library)

npm install jssb-cli

CLI Usage

After global installation, use the jssb command:

# Basic usage - generates input-name.schema.json
jssb data.json

# Specify custom output file
jssb data.json --output my-schema.json

# With custom title and options
jssb data.json --title "User Schema" --no-examples --infer-enums

CLI Options

| Option | Short | Description | Default | |--------|-------|-------------|---------| | --output | -o | Output file path | <input-name>.schema.json | | --title | -t | Schema title | Derived from filename | | --no-examples | | Exclude examples from schema | Include examples | | --no-format | | Disable format detection | Format detection enabled | | --no-required | | Don't mark properties as required | Mark as required | | --additional-props | | Allow additional properties | Disallow additional properties | | --infer-enums | | Enable enum inference | Disabled | | --enum-threshold | | Max unique values for enums | 5 | | --help | -h | Show help message | |

CLI Examples

# Generate schema for user data
jssb user.json

# Custom output location
jssb data/users.json --output schemas/user.schema.json

# With enum detection for repeated values
jssb config.json --infer-enums --enum-threshold 3

# Minimal schema without examples
jssb api-response.json --no-examples --title "API Response"

Library Usage

import { JsonSchemaBuilder } from 'jsonschema-builder';

const builder = new JsonSchemaBuilder({
  includeExamples: true,
  detectFormat: true,
  requiredByDefault: true,
  additionalProperties: false
});

const sampleData = {
  name: 'John Doe',
  age: 30,
  email: '[email protected]',
  hobbies: ['reading', 'coding']
};

const schema = builder.build(sampleData, 'User');
console.log(JSON.stringify(schema, null, 2));

Features

  • Complex nested objects - Handles deep nesting and complex structures
  • Array support - Mixed types, nested arrays, unique item detection
  • Format detection - Email, URL, date, UUID, IP addresses
  • Multiple samples - Build schemas from multiple JSON samples
  • Enum inference - Detect repeated values and create enums
  • Type validation - Strict TypeScript types
  • CLI tool - Easy command-line usage
  • Configurable - Many options to customize output

Supported Formats

  • email - [email protected]
  • uri - https://example.com
  • date - 2024-01-15
  • date-time - 2024-01-15T10:30:00.000Z
  • uuid - 550e8400-e29b-41d4-a716-446655440000
  • ipv4 - 192.168.1.1
  • ipv6 - 2001:0db8:85a3:0000:0000:8a2e:0370:7334

Configuration Options

interface SchemaBuilderOptions {
  includeExamples?: boolean;     // Include sample values (default: true)
  detectFormat?: boolean;        // Auto-detect string formats (default: true)
  requiredByDefault?: boolean;   // Mark properties as required (default: true)
  additionalProperties?: boolean; // Allow additional properties (default: false)
  inferEnums?: boolean;          // Detect enum patterns (default: false)
  enumThreshold?: number;        // Max unique values for enums (default: 5)
}

Examples

Input JSON

{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "user": {
    "name": "John Doe",
    "email": "[email protected]",
    "createdAt": "2024-01-15T10:30:00.000Z"
  },
  "tags": ["premium", "verified"]
}

Generated Schema

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "title": "User",
  "properties": {
    "id": {
      "type": "string",
      "format": "uuid"
    },
    "user": {
      "type": "object",
      "properties": {
        "name": { "type": "string" },
        "email": { "type": "string", "format": "email" },
        "createdAt": { "type": "string", "format": "date-time" }
      },
      "required": ["name", "email", "createdAt"],
      "additionalProperties": false
    },
    "tags": {
      "type": "array",
      "items": { "type": "string" },
      "uniqueItems": true
    }
  },
  "required": ["id", "user", "tags"],
  "additionalProperties": false
}

Development

# Install dependencies
npm install

# Build TypeScript
npm run build

# Run examples
npm run example

# Link for local testing
npm link

License

MIT