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

@fillament/json-schema

v0.3.0

Published

JSON Schema validation adapter for Fillament — AJV-backed, with ajv-formats.

Downloads

305

Readme

@fillament/json-schema

JSON Schema validation adapter for Fillament. Backed by Ajv + ajv-formats. Pass a JSON Schema, get a Fillament ValidationAdapter you can hand to useForm.

pnpm add @fillament/json-schema
import { useForm } from "@fillament/react";
import { jsonSchemaAdapter } from "@fillament/json-schema";

const schema = {
  type: "object",
  required: ["email"],
  properties: {
    email: { type: "string", format: "email" },
    age:   { type: "integer", minimum: 18 },
    role:  { type: "string", enum: ["dev", "designer"] },
  },
};

const form = useForm({ schema: jsonSchemaAdapter(schema) });

Exports

| Export | Kind | Purpose | | --- | --- | --- | | jsonSchemaAdapter(schema, options?) | factory | Returns a ValidationAdapter for the given JSON Schema. | | JsonSchema | type | Record<string, unknown> — alias for the JSON-schema-shaped object. | | JsonSchemaAdapterOptions | type | Adapter options. | | Ajv | type | Re-export of Ajv's Ajv type for typing custom instances. |


jsonSchemaAdapter(schema, options?)

JsonSchemaAdapterOptions

| Option | Type | Default | Notes | | --- | --- | --- | --- | | ajv | Ajv | — | Pre-configured Ajv instance — pass one to share schemas, custom keywords, or formats across your app. | | ajvOptions | Ajv.Options | { allErrors: true, strict: false } | Options forwarded to Ajv when constructing a fresh instance. Your overrides merge on top. | | noFormats | boolean | false | Skip auto-registering ajv-formats. Only relevant when you didn't pass your own ajv. |

Returns a ValidationAdapter<TValues> with type: "json-schema". Pass it directly as useForm({ schema: jsonSchemaAdapter(s) }).

The adapter also implements introspect(), returning your schema verbatim. Optional modules use it to discover the form's shape — @fillament/webmcp publishes it to AI agents as a tool schema, and @fillament/test-data generates fixtures from it. Since the schema is JSON Schema, this adapter gives those modules the highest-fidelity picture of any adapter.


How errors are mapped

| AJV concept | Fillament concept | | --- | --- | | instancePath (/contacts/0/name) | path (contacts.0.name) | | keyword (required, minLength, format, …) | FormError.code | | message (must match format "email") | FormError.message | | params.missingProperty for required errors | Appended to the path so the error lands on the missing field, not the parent. | | Schema-path metadata | FormError.meta.schemaPath |

All errors are tagged type: "schema", source: "schema". validate() returns the full ValidationResult; field-level validateField(name, value, values) runs the full validate and slices the result, including any child errors (e.g. validating "address" surfaces "address.city is required").


Custom Ajv setup

Bring your own Ajv when you need keywords, formats, or shared compilation across schemas:

import Ajv from "ajv";
import addFormats from "ajv-formats";
import { jsonSchemaAdapter } from "@fillament/json-schema";

const ajv = new Ajv({ allErrors: true, strict: false });
addFormats(ajv);
ajv.addFormat("phone-pt", /^\+351\s?9\d{8}$/);
ajv.addKeyword({ keyword: "isUUID", validate: (_s: any, v: any) => typeof v === "string" });

const adapter = jsonSchemaAdapter(MySchema, { ajv });

When you pass your own ajv, noFormats is ignored — Fillament does not touch the instance.


Conditional / advanced schemas

JSON Schema features that Ajv supports work out of the box:

  • oneOf / anyOf / allOf — first matching schema wins for error reporting.
  • if / then / else — conditional validation.
  • $ref — local and remote references (configure Ajv accordingly).
  • dependencies, propertyNames, patternProperties, additionalProperties.

For complex error UX (e.g. picking a specific oneOf branch's error to show), consume FormError.meta.params and FormError.meta.schemaPath.


Type inference

jsonSchemaAdapter is generic over TValues:

type UserValues = {
  email: string;
  age: number;
  role: "dev" | "designer";
};

const form = useForm({
  schema: jsonSchemaAdapter<UserValues>(MySchema),
});

The adapter doesn't infer the type from the schema (JSON Schema → TS inference would require a heavy library). Pass <UserValues> explicitly when you want field-path checking — form.setValue("email", …) then gets the usual Fillament type safety.


Performance

  • Ajv compiles the schema once on jsonSchemaAdapter(schema). Re-creating the adapter on every render compiles every render — memoize it:
    const adapter = useMemo(() => jsonSchemaAdapter(MySchema), []);
  • validate and validateField share the compiled validator. Field-level validation is a slice of the full run.

License

MIT © headlessButSmart