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 🙏

© 2025 – Pkg Stats / Ryan Hefner

json-schema-to-form

v0.0.1

Published

Generate HTML form markup from JSON Schema.

Readme

json-schema-to-form

Generate HTML form markup from JSON Schema.

What it does

  • Render a JSON Schema to form controls (any valid JSON Schema is supported)
    • Use as JSX components (RenderSchemaToHonoForm, RenderSchemaToHonoElements)
    • Or produce plain strings (convertSchemaToFormString, convertSchemaToString)
  • Normalize FormData into a nested object (normalizeFormData)

Install

Install the library (add zod only if you plan to derive JSON Schema from Zod, and ajv only if you implement validation yourself):

npm i json-schema-to-form hono
# Optional:
npm i zod
npm i ajv

Quick start

Render a form string from JSON Schema:

import {
  convertSchemaToFormString,
  type ObjectSchema,
} from "json-schema-to-form";

const schema = {
  type: "object",
  properties: {
    url: { type: "string", format: "uri" },
    method: {
      type: "string",
      enum: ["GET", "POST"],
      default: "POST",
      uiWidget: "select",
    },
    user: {
      type: "object",
      properties: {
        name: { type: "string", minLength: 1, maxLength: 100 },
        age: { type: "number", minimum: 0, maximum: 120, uiWidget: "range" },
      },
    },
  },
} satisfies ObjectSchema;

// Equivalent with Zod (optional):
const S = z.object({
  url: z.url(),
  method: z.enum(["GET", "POST"]).default("POST").meta({ uiWidget: "select" }),
  user: z.object({
    name: z.string().min(1).max(100),
    age: z.number().min(0).max(120).meta({ uiWidget: "range" }),
  }),
});
const schema = z.toJSONSchema(S) as ObjectSchema;

const html: string = convertSchemaToFormString(schema, {
  method: "post",
  action: "/submit",
});

Use directly as JSX with Hono:

import { Hono } from "hono";
import { html } from "hono/html";
import {
  RenderSchemaToHonoForm,
  RenderSchemaToHonoElements,
  type ObjectSchema,
} from "json-schema-to-form";

const app = new Hono();
const schema: ObjectSchema = {
  type: "object",
  properties: {
    url: { type: "string", format: "uri" },
    bio: { type: "string", uiWidget: "textarea" },
  },
};

app.get("/", (c) =>
  c.html(
    html`<html>
      <body>
        ${html`${(
          <RenderSchemaToHonoForm
            schema={schema}
            method="post"
            action="/submit"
          >
            <button type="submit">Submit</button>
          </RenderSchemaToHonoForm>
        )}`}
      </body>
    </html>`
  )
);

// If you prefer not use JSX:
const htmlString: string = RenderSchemaToHonoElements({
  schema,
  method: "post",
  action: "/submit",
}).toString();

Normalize submitted data (validation is app-owned):

import { normalizeFormData } from "json-schema-to-form";

app.post("/submit", async (c) => {
  const fd = await c.req.formData();
  const input = normalizeFormData(fd);
});

// If you need validation, wire up Ajv yourself (not exported by this package)
// Example: see `src/validate.ts` in this repo for a utility you can copy.

Schema metadata

You can influence rendering via JSON Schema metadata (when using zod, attach via .meta):

  • uiWidget: string – preferred input widget, e.g., textarea, select, radio, range.
  • uiName: string – displayed label text; falls back to the property key.
  • description: string – used for title or hint text where appropriate.

API

  • convertSchemaToString(schema) – render fields (no <form>) and return a string
  • convertSchemaToFormString(schema, props?) – render a complete <form> string
  • RenderSchemaToHonoForm – JSX component rendering a <form> and fields
  • RenderSchemaToHonoElements – JSX fragment rendering only fields
  • normalizeFormData(formData) – turn FormData into a nested object

Validation helpers are NOT exported by this package.

Limitations

  • Root schema must be { type: "object", properties }.
  • Arrays must specify items.enum; arrays of object or array are not supported.
  • Supported string formats: uri, email, date-time-local, time-local.
  • File inputs cannot be represented in JSON; validation may need custom handling.