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-form-react

v0.0.2

Published

A tiny (4.5kb minified, 1.6kb gzipped) dependency-free json schema form library for react to validate `FormData` against a JSON Schema.

Readme

json-schema-form-react

A tiny (4.5kb minified, 1.6kb gzipped) dependency-free json schema form library for react to validate FormData against a JSON Schema.

Motivation

There are several libraries helping with JSON Schema and forms, but most focus on autogenerating them. While this is very handy at first, you'll find yourself digging deep into the documentation to customize the generated forms. On the other hand, there are libraries for form management, each with its very own API to learn.

This library aims to be a minimal abstraction between native browser forms and JSON schema. In addition, it doesn't assume or require deep understanding of validation libraries, it's very easy to use any JSON schema validator. Create a class with a validate function that takes in the schema and form data, returning the error schema (and inferring the type correctly) that library provides – no transformation needed.

Installation

npm install json-schema-form-react

Usage

Here is a minimal example to get it running using json-schema-library as the validator (you can use any):

import type { JsonError, JsonSchema } from "json-schema-library";
import { Draft2019 } from "json-schema-library";
import { Form, type Validator } from "json-schema-form-react";

// using json-schema-library, but could be any
class JsonValidator implements Validator<JsonError> {
   async validate(schema: JsonSchema, data: any) {
      return new Draft2019(schema).validate(data);
   }
}
const validator = new JsonValidator();

const schema = {
   type: "object",
   properties: {
      name: { type: "string" },
      age: { type: "number", minimum: 1 },
   },
   required: ["name"],
} satisfies JsonSchema;

export default function App() {
   return (
      <Form
         schema={schema}
         onChange={console.log}
         onSubmit={console.log}
         validator={validator}
         validationMode="change"
      >
         {({ errors, dirty, reset }) => (
            <>
               <div>
                  <b>
                     Form {dirty ? "*" : ""} (valid:{" "}
                     {errors.length === 0 ? "valid" : "invalid"})
                  </b>
               </div>
               <div>
                  <input type="text" name="name" />
                  <input type="number" name="age" />
               </div>
               <div>
                  <button type="submit">submit</button>
                  <button type="button" onClick={reset}>
                     reset
                  </button>
               </div>
            </>
         )}
      </Form>
   );
}

Validators

A custom validator can be created by implementing the Validator interface:

type Validator<Err = unknown, FormData = any> = {
   validate: (
      schema: JSONSchema | any,
      data: FormData
   ) => Promise<Err[]> | Err[];
};

json-schema-library

The example above uses json-schema-library to validate the form data against a JSON Schema. The validator implements the Validator interface:

import type { Validator } from "json-schema-form-react";
import { Draft2019 } from "json-schema-library";

class JsonValidator implements Validator<JsonError> {
   async validate(schema: JsonSchema, data: any) {
      return new Draft2019(schema).validate(data);
   }
}

@sinclair/typebox

Here's an example validator implementation using TypeBox:

import type { Validator } from "json-schema-form-react";
import { Value } from "@sinclair/typebox/value";

class TypeboxValidator implements Validator<ValueError> {
   async validate(schema: TSchema, data: any) {
      return Value.Check(schema, data) ? [] : [...Value.Errors(schema, data)];
   }
}

Todos

It's very early, there are some functionalities planned:

  • [ ] add an error map to identify the erroring field easily
  • [ ] add a complementary library to automatically generate the form, with the freedom of modifying the layout and props inline
  • [ ] more examples for various validation and UI libraries