Schema
Schema

Overview

A package for working with Zod (new tab) and JSON Schemas (new tab).
It ships many small helpers for a schema-first approach to building user interfaces.

npm versionnpm downloadsBundlephobia

Installation

# npm
npm i --save @weser/schema

# yarn
yarn add @weser/schema

# pnpm
pnpm add @weser/schema

Motivation

Schema validation is a core part of any modern, type-safe application. With Zod as a popular and powerful library, we can do all sorts of things from API requests to form validation.
However, since everything is stored as objects and functions, we can't really store them in a database or iterate over them in a more straight forward way. That's where this package comes in. It ships a set of helpers for converting Zod schemas to JSON Schemas and vice versa for full end-to-end type safety.

Benefits

Being able to turn complex Zod schemas into JSON Schemas comes with two main benefits:

  1. Being able to store the schema in a database
  2. Being able to iterate over the schema in a more straight forward way

This allows for a schema-first approach where the schema is the single source of truth and the UI is generated based on it.

On this page