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

@ht-rnd/json-schema-editor

v2.0.4

Published

Headless JSON Schema Editor - provides hooks and utilities for building JSON Schema editors

Readme

@ht-rnd/json-schema-editor

A powerful headless JSON Schema editor for React. Build fully customized editors with complete UI control while leveraging battle-tested logic, validation, and state management.

Headless Architecture: Core logic via npm + optional copy-paste UI components. Use our pre-built Shadcn/ui components or build your own interface.

Features

  • Multi-Draft Support - Draft-07, 2019-09, and 2020-12 with automatic detection via $schema URI
  • All Types - string, number, integer, boolean, object, array, $ref
  • Nested Schemas - Unlimited depth for objects and arrays
  • $defs / definitions Support - Reusable definitions with $ref; emits the correct key per draft
  • Validation - AJV-powered real-time draft-aware validation
  • Combinators - allOf, anyOf, oneOf, not
  • TypeScript - Full type safety
  • Headless - Zero UI dependencies in core

Installation

npm install @ht-rnd/json-schema-editor

Optional UI components: Copy components/ui/ from this repo to your project. Requires Radix UI and Tailwind CSS.

Quick Start

Option 1: Pre-built Components

import { JsonSchemaEditor } from "@/components/ui/json-schema-editor";

function App() {
  return (
    <JsonSchemaEditor
      rootType="object"
      onChange={(schema) => console.log(schema)}
    />
  );
}

Option 2: Headless Hook

import { useJsonSchemaEditor } from "@ht-rnd/json-schema-editor";
import { FormProvider } from "react-hook-form";

function App() {
  const editor = useJsonSchemaEditor({
    rootType: "object",
    onChange: (schema) => console.log(schema),
  });

  return (
    <FormProvider {...editor.form}>
      <button onClick={editor.addField}>Add Field</button>
      {editor.fields.map((field, index) => (
        <div key={field.id}>
          <input value={field.key} />
          <button onClick={() => editor.removeField(index)}>Remove</button>
        </div>
      ))}
      <pre>{JSON.stringify(editor.schema, null, 2)}</pre>
    </FormProvider>
  );
}

API Reference

useJsonSchemaEditor(options)

Main hook for editor state management.

Options:

{
  rootType?: "object" | "array";  // Default: "object"
  defaultValue?: JSONSchema;       // Load existing schema
  onChange?: (schema: JSONSchema) => void;
}

Returns:

{
  // State
  schema: JSONSchema;
  errors: SchemaError[] | null;  // null when valid
  fields: FieldItem[];
  definitions: DefinitionItem[];
  form: UseFormReturn;
  settingsState: { isOpen: boolean; fieldPath: string | null };

  // Actions
  addField: () => void;
  removeField: (index: number) => void;
  addDefinition: () => void;
  removeDefinition: (index: number) => void;
  updateReferences: (oldKey: string, newKey: string | null) => void;  // update $ref strings when a definition key changes
  openSettings: (path: string) => void;
  closeSettings: () => void;
  handleTypeChange: (path: string, type: string) => void;
  addNestedField: (parentPath: string) => void;
  reset: () => void;
}

JsonSchemaEditor Component Props

| Prop | Type | Default | Description | |------|------|---------|-------------| | rootType | "object" \| "array" | "object" | Root schema type | | defaultValue | JSONSchema | - | Initial schema to load | | onChange | (schema) => void | - | Callback on schema change | | readOnly | boolean | false | View-only mode | | showOutput | boolean | true | Show/hide JSON output panel | | defaultOutputCollapsed | boolean | false | Start the JSON output panel collapsed | | className | string | - | Additional CSS classes |

Exports

// Main hook
export { useJsonSchemaEditor } from "@ht-rnd/json-schema-editor";

// Types
export type { JSONSchema, FieldItem, DefinitionItem, UseJsonSchemaEditorReturn };

// Utilities (all draft-aware: select AJV instance / emit correct defs key based on $schema)
export { validateSchema, formToSchema, schemaToForm };

// Constants
export { SCHEMA_TYPES, STRING_FORMATS, NUMBER_FORMATS, INTEGER_FORMATS };

Examples

Load Existing Schema

const editor = useJsonSchemaEditor({
  rootType: "object",
  defaultValue: {
    type: "object",
    properties: {
      username: { type: "string", minLength: 3 },
      email: { type: "string", format: "email" },
      age: { type: "integer", minimum: 18 }
    },
    required: ["username", "email"]
  }
});

Validate Data Against Schema

import Ajv from "ajv";

const ajv = new Ajv();
const validate = ajv.compile(editor.schema);
const valid = validate({ username: "john", email: "[email protected]" });

if (!valid) console.log(validate.errors);

Persist Schema Changes

const editor = useJsonSchemaEditor({
  onChange: (schema) => {
    localStorage.setItem("schema", JSON.stringify(schema));
    // Or send to API
  }
});

Contributing

Contributions welcome! See GitHub for issues and PRs.

git clone https://github.com/ht-rnd/json-schema-editor.git
npm install
npm test
npm run demo

License

Apache-2.0 © [HT-RND]

See LICENSE for more details.