JSON to Valibot

Input
Output

JSON to Valibot

Paste a JSON sample, such as an API response, and Bracely writes Valibot schemas and TypeScript types for it. Each object becomes a v.object() schema with an inferred output type, written with Valibot's small functions so a bundler keeps only the ones you use.

Example: an editor's settings, validated in the browser

A settings object kept in local storage. Each object becomes a v.object() schema and a whole number becomes v.pipe(v.number(), v.integer()), so a hand-edited value like 14.5 is caught:

Input

{
  "theme": "dark",
  "fontSize": 14,
  "autosave": true,
  "shortcuts": {
    "save": "Ctrl+S",
    "search": "Ctrl+K"
  },
  "recentFiles": [
    "orders.json",
    "users.csv"
  ]
}

Output

import * as v from "valibot";

export const ShortcutsSchema = v.object({
  save: v.string(),
  search: v.string(),
});
export type Shortcuts = v.InferOutput<typeof ShortcutsSchema>;

export const SettingsSchema = v.object({
  theme: v.string(),
  fontSize: v.pipe(v.number(), v.integer()),
  autosave: v.boolean(),
  shortcuts: ShortcutsSchema,
  recentFiles: v.array(v.string()),
});
export type Settings = v.InferOutput<typeof SettingsSchema>;

How do I use the JSON to Valibot?

  1. Paste a JSON sample.
  2. Set the root type name, for example Order.
  3. Copy the Valibot code into your project.

What does the JSON to Valibot do?

  • v.object schemas in dependency order
  • v.InferOutput types exported for each
  • v.optional and v.pipe(v.number(), v.integer()) from your data
  • Nested objects become their own named types
  • 20 other languages from the same sample, including TypeScript

When to use the JSON to Valibot

Valibot validates data like Zod but is built from small separate functions, so a bundler keeps only the ones your schemas use. That matters in browser code, edge functions and widgets where every kilobyte counts. Paste the JSON you need to check, such as settings from local storage or an API response, and copy schemas for it.

Each object becomes a v.object() schema, written in dependency order so each is defined before it's used, with v.InferOutput giving its TypeScript type. Whole numbers become v.pipe(v.number(), v.integer()), so 14.5 fails where 14 is expected. Fields missing from some items are v.optional(), and values that are sometimes null are v.nullable().

Frequently asked questions

How do I check data with the schema?
v.parse(SettingsSchema, data) returns the typed value or throws; v.safeParse(SettingsSchema, data) returns a result with success and issues instead, which suits forms and stored data you don't want to crash on.
Valibot or Zod?
Both describe the same things. Zod is the most widely used; Valibot is designed for small bundles. Bracely writes either from the same sample: change Language to Zod.
How does it pick Valibot types?
From the values in your sample: whole numbers, decimals, text, true/false, arrays and nested objects. When array items disagree, the field is made optional or widened.
Can I generate other languages?
Yes. Change Language to any of the others: TypeScript, Go, Python, Pydantic, Java, C#, Kotlin, Swift, Rust, Scala, Ruby, Dart, PHP, Zod, TypeBox, Yup, GraphQL, Protobuf, Prisma and Drizzle.
Is my data uploaded?
No. Bracely runs entirely in your browser, so nothing you paste or open leaves your device.

More JSON tools

Bracely has 104 JSON tools in one page. Related ones:

Runs entirely in your browser. Nothing you paste is uploaded. Made by Saurabh Pagrut · About · Privacy policy
Last updated · Version 6.1 · Changelog
Saurabh Pagrut on GitHub · LinkedIn · X · YouTube · Instagram