Schema.Codec<JsonValue, JsonValue, never, never>Recursive structural JSON value schema — decodes to JsonValue. Used for the option
attributes, which the engine persists as JSON. Schema.suspend breaks the self-reference.
export const const jsonValue: Schema.Codec<
JsonValue,
JsonValue,
never,
never
>
const jsonValue: {
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
Rebuild: Codec<T, E, RD, RE>;
Type: T;
Iso: Iso;
ast: Ast;
annotate: (annotations: Schema.Annotations.Bottom<JsonValue, any>) => Schema.Codec<JsonValue, JsonValue, never, never>;
annotateKey: (annotations: Schema.Annotations.Key<JsonValue>) => Schema.Codec<JsonValue, JsonValue, never, never>;
check: (checks_0: Check<JsonValue>, ...checks: Array<Check<JsonValue>>) => Schema.Codec<JsonValue, JsonValue, never, never>;
rebuild: (ast: AST) => Schema.Codec<JsonValue, JsonValue, never, never>;
make: (input: unknown, options?: Schema.MakeOptions) => JsonValue;
makeOption: (input: unknown, options?: Schema.MakeOptions) => Option.Option<JsonValue>;
makeEffect: (input: unknown, options?: Schema.MakeOptions) => Effect.Effect<JsonValue, Schema.SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
Recursive structural JSON value schema — decodes to
JsonValue
. Used for the option
attributes, which the engine persists as JSON. Schema.suspend breaks the self-reference.
jsonValue: import SchemaSchema.interface Codec<out T, out E = T, out RD = never, out RE = never>Namespace of type-level helpers for
Codec
.
A schema that tracks the decoded type T, the encoded type E, and the
Effect services required during decoding (RD) and encoding (RE).
Details
Use Codec<T, E, RD, RE> when you need to preserve full type information
about a schema — both what it decodes to and what it serializes from/to.
Most concrete schemas produced by this module implement Codec.
For APIs that only need one direction, prefer the narrower views:
Decoder
<T, RD> — decode-only
Encoder
<E, RE> — encode-only
Schema
<T> — type-only (no encoded representation)
Example (Accepting a codec that decodes to number from string)
import { Schema } from "effect"
declare function serialize<T>(codec: Schema.Codec<T, string>): string
serialize(Schema.NumberFromString) // ok — decodes number, encoded as string
Codec<import JsonValueJsonValue> = import SchemaSchema.function Union<readonly [Schema.Null, Schema.String, Schema.Number, Schema.Boolean, Schema.$Record<Schema.String, Schema.suspend<Schema.Codec<JsonValue, JsonValue, never, never>>>, Schema.$Array<Schema.suspend<Schema.Codec<JsonValue, JsonValue, never, never>>>]>(members: readonly [Schema.Null, Schema.String, Schema.Number, Schema.Boolean, Schema.$Record<Schema.String, Schema.suspend<Schema.Codec<JsonValue, JsonValue, never, never>>>, Schema.$Array<Schema.suspend<Schema.Codec<JsonValue, JsonValue, never, never>>>], options?: {
mode?: "anyOf" | "oneOf";
}): Schema.Union<...>
Creates a union schema from an array of member schemas. Members are tested in
order; the first match is returned.
Details
Optionally, specify mode:
"anyOf" (default) — matches if any member matches.
"oneOf" — matches if exactly one member matches.
Example (Defining a string or number union)
import { Schema } from "effect"
const schema = Schema.Union([Schema.String, Schema.Number])
Schema.decodeUnknownSync(schema)("hello") // "hello"
Schema.decodeUnknownSync(schema)(42) // 42
Union([
import SchemaSchema.const Null: Schema.Nullconst Null: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<null, readonly []>) => Schema.Null;
annotateKey: (annotations: Schema.Annotations.Key<null>) => Schema.Null;
check: (checks_0: Check<null>, ...checks: Array<Check<null>>) => Schema.Null;
rebuild: (ast: Null) => Schema.Null;
make: (input: null, options?: Schema.MakeOptions) => null;
makeOption: (input: null, options?: Schema.MakeOptions) => Option.Option<null>;
makeEffect: (input: null, options?: Schema.MakeOptions) => Effect.Effect<null, Schema.SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
Type-level representation of
Null
.
Schema for the null literal. Validates that the input is strictly null.
Null,
import SchemaSchema.const String: Schema.Stringconst String: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<string, readonly []>) => Schema.String;
annotateKey: (annotations: Schema.Annotations.Key<string>) => Schema.String;
check: (checks_0: Check<string>, ...checks: Array<Check<string>>) => Schema.String;
rebuild: (ast: String) => Schema.String;
make: (input: string, options?: Schema.MakeOptions) => string;
makeOption: (input: string, options?: Schema.MakeOptions) => Option.Option<string>;
makeEffect: (input: string, options?: Schema.MakeOptions) => Effect.Effect<string, Schema.SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
Type-level representation of
String
.
Schema for string values. Validates that the input is typeof "string".
String,
import SchemaSchema.const Number: Schema.Numberconst Number: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<number, readonly []>) => Schema.Number;
annotateKey: (annotations: Schema.Annotations.Key<number>) => Schema.Number;
check: (checks_0: Check<number>, ...checks: Array<Check<number>>) => Schema.Number;
rebuild: (ast: Number) => Schema.Number;
make: (input: number, options?: Schema.MakeOptions) => number;
makeOption: (input: number, options?: Schema.MakeOptions) => Option.Option<number>;
makeEffect: (input: number, options?: Schema.MakeOptions) => Effect.Effect<number, Schema.SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
Type-level representation of
Number
.
Schema for number values, including NaN, Infinity, and -Infinity.
Details
Default JSON serializer:
- Finite numbers are serialized as numbers.
- Non-finite values are serialized as strings (
"NaN", "Infinity", "-Infinity").
Number,
import SchemaSchema.const Boolean: Schema.Booleanconst Boolean: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<boolean, readonly []>) => Schema.Boolean;
annotateKey: (annotations: Schema.Annotations.Key<boolean>) => Schema.Boolean;
check: (checks_0: Check<boolean>, ...checks: Array<Check<boolean>>) => Schema.Boolean;
rebuild: (ast: Boolean) => Schema.Boolean;
make: (input: boolean, options?: Schema.MakeOptions) => boolean;
makeOption: (input: boolean, options?: Schema.MakeOptions) => Option.Option<boolean>;
makeEffect: (input: boolean, options?: Schema.MakeOptions) => Effect.Effect<boolean, Schema.SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
Type-level representation of
Boolean
.
Schema for boolean values. Validates that the input is typeof "boolean".
When to use
Use to validate values that are already JavaScript booleans.
Boolean,
import SchemaSchema.function Record<Schema.String, Schema.suspend<Schema.Codec<JsonValue, JsonValue, never, never>>>(key: Schema.String, value: Schema.suspend<Schema.Codec<JsonValue, JsonValue, never, never>>, options?: {
readonly keyValueCombiner: {
readonly decode?: Combiner<readonly [string, JsonValue]> | undefined;
readonly encode?: Combiner<readonly [string, JsonValue]> | undefined;
};
} | undefined): Schema.$Record<Schema.String, Schema.suspend<Schema.Codec<JsonValue, JsonValue, never, never>>>
Defines a record schema whose dynamic properties are selected by a key schema
and decoded with a value schema.
Details
For dynamic keys, the key schema selects matching own properties and the
value schema decodes or encodes only those selected properties. Checks on
string, number, symbol, and template literal key schemas narrow which
properties are selected.
For transformed key schemas, property selection is based on encoded property
names before the selected key is decoded.
Example (Defining a string-keyed record of numbers)
import { Schema } from "effect"
const schema = Schema.Record(Schema.String, Schema.Number)
// { readonly [x: string]: number }
type R = typeof schema.Type
const result = Schema.decodeUnknownSync(schema)({ a: 1, b: 2 })
console.log(result)
// { a: 1, b: 2 }
Record(
import SchemaSchema.const String: Schema.Stringconst String: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<string, readonly []>) => Schema.String;
annotateKey: (annotations: Schema.Annotations.Key<string>) => Schema.String;
check: (checks_0: Check<string>, ...checks: Array<Check<string>>) => Schema.String;
rebuild: (ast: String) => Schema.String;
make: (input: string, options?: Schema.MakeOptions) => string;
makeOption: (input: string, options?: Schema.MakeOptions) => Option.Option<string>;
makeEffect: (input: string, options?: Schema.MakeOptions) => Effect.Effect<string, Schema.SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
Type-level representation of
String
.
Schema for string values. Validates that the input is typeof "string".
String,
import SchemaSchema.function suspend<Schema.Codec<JsonValue, JsonValue, never, never>>(f: () => Schema.Codec<JsonValue, JsonValue, never, never>): Schema.suspend<Schema.Codec<JsonValue, JsonValue, never, never>>Creates a suspended schema that defers evaluation until needed. This is
essential for creating recursive schemas where a schema references itself,
preventing infinite recursion during schema definition.
Example (Defining recursive tree schemas)
import { Schema } from "effect"
interface Tree {
readonly value: number
readonly children: ReadonlyArray<Tree>
}
const Tree = Schema.Struct({
value: Schema.Number,
children: Schema.Array(Schema.suspend((): Schema.Codec<Tree> => Tree))
})
suspend((): import SchemaSchema.interface Codec<out T, out E = T, out RD = never, out RE = never>Namespace of type-level helpers for
Codec
.
A schema that tracks the decoded type T, the encoded type E, and the
Effect services required during decoding (RD) and encoding (RE).
Details
Use Codec<T, E, RD, RE> when you need to preserve full type information
about a schema — both what it decodes to and what it serializes from/to.
Most concrete schemas produced by this module implement Codec.
For APIs that only need one direction, prefer the narrower views:
Decoder
<T, RD> — decode-only
Encoder
<E, RE> — encode-only
Schema
<T> — type-only (no encoded representation)
Example (Accepting a codec that decodes to number from string)
import { Schema } from "effect"
declare function serialize<T>(codec: Schema.Codec<T, string>): string
serialize(Schema.NumberFromString) // ok — decodes number, encoded as string
Codec<import JsonValueJsonValue> => const jsonValue: Schema.Codec<
JsonValue,
JsonValue,
never,
never
>
const jsonValue: {
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
Rebuild: Codec<T, E, RD, RE>;
Type: T;
Iso: Iso;
ast: Ast;
annotate: (annotations: Schema.Annotations.Bottom<JsonValue, any>) => Schema.Codec<JsonValue, JsonValue, never, never>;
annotateKey: (annotations: Schema.Annotations.Key<JsonValue>) => Schema.Codec<JsonValue, JsonValue, never, never>;
check: (checks_0: Check<JsonValue>, ...checks: Array<Check<JsonValue>>) => Schema.Codec<JsonValue, JsonValue, never, never>;
rebuild: (ast: AST) => Schema.Codec<JsonValue, JsonValue, never, never>;
make: (input: unknown, options?: Schema.MakeOptions) => JsonValue;
makeOption: (input: unknown, options?: Schema.MakeOptions) => Option.Option<JsonValue>;
makeEffect: (input: unknown, options?: Schema.MakeOptions) => Effect.Effect<JsonValue, Schema.SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
Recursive structural JSON value schema — decodes to
JsonValue
. Used for the option
attributes, which the engine persists as JSON. Schema.suspend breaks the self-reference.
jsonValue),
),
import SchemaSchema.Array<Schema.suspend<Schema.Codec<JsonValue, JsonValue, never, never>>>(self: Schema.suspend<Schema.Codec<JsonValue, JsonValue, never, never>>): Schema.$Array<Schema.suspend<Schema.Codec<JsonValue, JsonValue, never, never>>>
export Array
Defines a ReadonlyArray schema for a given element schema.
Example (Defining an array of strings)
import { Schema } from "effect"
const schema = Schema.Array(Schema.String)
const result = Schema.decodeUnknownSync(schema)(["a", "b", "c"])
console.log(result)
// [ 'a', 'b', 'c' ]
Array(import SchemaSchema.function suspend<Schema.Codec<JsonValue, JsonValue, never, never>>(f: () => Schema.Codec<JsonValue, JsonValue, never, never>): Schema.suspend<Schema.Codec<JsonValue, JsonValue, never, never>>Creates a suspended schema that defers evaluation until needed. This is
essential for creating recursive schemas where a schema references itself,
preventing infinite recursion during schema definition.
Example (Defining recursive tree schemas)
import { Schema } from "effect"
interface Tree {
readonly value: number
readonly children: ReadonlyArray<Tree>
}
const Tree = Schema.Struct({
value: Schema.Number,
children: Schema.Array(Schema.suspend((): Schema.Codec<Tree> => Tree))
})
suspend((): import SchemaSchema.interface Codec<out T, out E = T, out RD = never, out RE = never>Namespace of type-level helpers for
Codec
.
A schema that tracks the decoded type T, the encoded type E, and the
Effect services required during decoding (RD) and encoding (RE).
Details
Use Codec<T, E, RD, RE> when you need to preserve full type information
about a schema — both what it decodes to and what it serializes from/to.
Most concrete schemas produced by this module implement Codec.
For APIs that only need one direction, prefer the narrower views:
Decoder
<T, RD> — decode-only
Encoder
<E, RE> — encode-only
Schema
<T> — type-only (no encoded representation)
Example (Accepting a codec that decodes to number from string)
import { Schema } from "effect"
declare function serialize<T>(codec: Schema.Codec<T, string>): string
serialize(Schema.NumberFromString) // ok — decodes number, encoded as string
Codec<import JsonValueJsonValue> => const jsonValue: Schema.Codec<
JsonValue,
JsonValue,
never,
never
>
const jsonValue: {
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
Rebuild: Codec<T, E, RD, RE>;
Type: T;
Iso: Iso;
ast: Ast;
annotate: (annotations: Schema.Annotations.Bottom<JsonValue, any>) => Schema.Codec<JsonValue, JsonValue, never, never>;
annotateKey: (annotations: Schema.Annotations.Key<JsonValue>) => Schema.Codec<JsonValue, JsonValue, never, never>;
check: (checks_0: Check<JsonValue>, ...checks: Array<Check<JsonValue>>) => Schema.Codec<JsonValue, JsonValue, never, never>;
rebuild: (ast: AST) => Schema.Codec<JsonValue, JsonValue, never, never>;
make: (input: unknown, options?: Schema.MakeOptions) => JsonValue;
makeOption: (input: unknown, options?: Schema.MakeOptions) => Option.Option<JsonValue>;
makeEffect: (input: unknown, options?: Schema.MakeOptions) => Effect.Effect<JsonValue, Schema.SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
Recursive structural JSON value schema — decodes to
JsonValue
. Used for the option
attributes, which the engine persists as JSON. Schema.suspend breaks the self-reference.
jsonValue)),
]);