Skip to content
ZeroServer.tools

JSON to Joi Schema

Generate a Joi validation schema from any JSON sample, ready to paste into your Node.js project.

About JSON to Joi Schema

This tool converts a JSON sample into a Joi validation schema for Node.js. Paste any JSON object and get a schema that covers strings, numbers, integers, booleans, nulls, nested objects, and arrays — all in one click. Toggle between .required() and .optional() to match your validation requirements. The generated schema is ready to copy directly into Express, Fastify, or any plain Node.js project that uses Joi for input validation.

Built and maintained by Meet Shah · Last updated

What this tool is used for

  • Generating a validation schema from a sample payload.
  • Producing a starting schema for an endpoint with no contract.
  • Seeing how nested objects map onto Joi's object syntax.
  • Creating a schema for a fixture that matches production shapes.
  • Comparing a generated schema against a hand-written one.

Frequently Asked Questions

What is Joi actually for?
RUNTIME validation of untrusted input in JavaScript — request bodies, config, form data. It is not a type system: it produces a validator object you call, and its guarantees exist at execution time, not at compile time.
How does it differ from JSON Schema?
JSON Schema is a declarative, language-agnostic DOCUMENT that any implementation can consume. Joi is JavaScript code with a fluent API. Joi is more expressive for custom rules; JSON Schema is portable and can be published as part of an API contract.
Should I use Joi or Zod now?
Zod has largely displaced it in TypeScript projects because it INFERS static types from the schema, so one definition gives both compile-time and runtime safety. Joi remains common in existing Node and Hapi codebases.
Are inferred rules complete?
No — generation from a sample can only see that sample. It cannot know a string is an email, a number has a maximum, or a field is conditionally required. Treat the output as a starting skeleton and add constraints.
Does Joi strip unknown keys?
Not by default — unknown keys cause a validation ERROR unless you set stripUnknown or allowUnknown. That default is deliberate and is a genuine security feature, since silently accepting extra fields invites mass-assignment bugs.
What does convert do?
By default Joi coerces — a string `"42"` passes `Joi.number()` and is returned as a number. Setting `convert: false` makes validation strict, which is usually what you want when the input is a JSON body rather than a query string.
How are conditional rules expressed?
With `when()`, which changes a field's schema based on another field's value — required only if a sibling is present, for instance. That is the main thing Joi can express naturally and a plain inferred schema cannot.

Common errors and gotchas

  • Accepting inferred `required`, which one sample cannot determine.
  • Letting a numeric string become `Joi.string()` when the API means a number.
  • Missing `unknown(true)` where extra keys are expected, so valid payloads are rejected.
  • Generating a schema that is stricter than the API, which then blocks legitimate requests.
  • Shipping without error messages, which makes validation failures unhelpful to a caller.

Related Developer Utilities tools

Private & free — this tool runs entirely in your browser.

IndieKitShip your Next.js startup in days.affiliate