Bidirectional by Design
Unlike other validation libraries, Schema handles both decoding (external β internal) and encoding (internal β external) with a single definition. Parse JSON, serialize to databases, or transform API responses seamlessly.
Define once. Decode, validate, encode, and transform data with full TypeScript inference. From the creators of Effect.
import { Schema } from "effect"
// Define a schema
const User = Schema.Struct({
name: Schema.String,
email: Schema.String.pipe(Schema.pattern(/@/)),
age: Schema.Number.pipe(Schema.int(), Schema.between(0, 120))
})
// TypeScript infers the type automatically
type User = typeof User.Type
// { readonly name: string; readonly email: string; readonly age: number }
// Decode unknown data safely
const result = Schema.decodeUnknownSync(User)({
name: "Alice",
email: "alice@example.com",
age: 30
})
// Encode back to plain objects
const encoded = Schema.encodeSync(User)(result)Most validation libraries stop at "is this valid?". Effect Schema goes further:
Every schema in Effect Schema has two types:
A): Your application's internal representationI): The external/serialized representationimport { Schema } from "effect"
// Schema<Date, string> β Type is Date, Encoded is string
const DateFromString = Schema.DateFromString
// Decode: string β Date
Schema.decodeSync(DateFromString)("2024-01-15") // Date object
// Encode: Date β string
Schema.encodeSync(DateFromString)(new Date()) // "2024-01-15T..."This bidirectional design means you define your transformations once and get both directions automatically.