Schema.Codec<Document, Schema.Json, never, never>Schema that decodes a Document from JSON and encodes it back.
When to use
Use when you need a JSON codec for schema representation documents with
Schema.decodeUnknownSync or Schema.encodeSync.
Example (Round-tripping a Document through JSON)
import { Schema, SchemaRepresentation } from "effect"
const doc = SchemaRepresentation.fromAST(Schema.String.ast)
const json = Schema.encodeSync(SchemaRepresentation.DocumentFromJson)(doc)
const back = Schema.decodeUnknownSync(SchemaRepresentation.DocumentFromJson)(json)export const const DocumentFromJson: Schema.Codec<
Document,
Schema.Json
>
const DocumentFromJson: {
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
Rebuild: Codec<T, E, RD, RE>;
Type: T;
Iso: Iso;
ast: Ast;
annotate: (annotations: Schema.Annotations.Bottom<Document, any>) => Schema.Codec<Document, Schema.Json, never, never>;
annotateKey: (annotations: Schema.Annotations.Key<Document>) => Schema.Codec<Document, Schema.Json, never, never>;
check: (checks_0: SchemaAST.Check<Document>, ...checks: Array<SchemaAST.Check<Document>>) => Schema.Codec<Document, Schema.Json, never, never>;
rebuild: (ast: SchemaAST.AST) => Schema.Codec<Document, Schema.Json, never, never>;
make: (input: unknown, options?: MakeOptions) => SchemaRepresentation.Document;
makeOption: (input: unknown, options?: MakeOptions) => Option_.Option<SchemaRepresentation.Document>;
makeEffect: (input: unknown, options?: MakeOptions) => Effect.Effect<SchemaRepresentation.Document, 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; <…;
}
Schema that decodes a
Document
from JSON and encodes it back.
When to use
Use when you need a JSON codec for schema representation documents with
Schema.decodeUnknownSync or Schema.encodeSync.
Example (Round-tripping a Document through JSON)
import { Schema, SchemaRepresentation } from "effect"
const doc = SchemaRepresentation.fromAST(Schema.String.ast)
const json = Schema.encodeSync(SchemaRepresentation.DocumentFromJson)(doc)
const back = Schema.decodeUnknownSync(SchemaRepresentation.DocumentFromJson)(json)
DocumentFromJson: 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<type Document = {
readonly representation: Representation
readonly references: References
}
A single
Representation
together with its named
References
.
When to use
Use when representing a single Schema AST together with its named references
before reconstructing a runtime Schema, converting to JSON Schema, or
wrapping it as a
MultiDocument
.
Document, import SchemaSchema.type Json =
| string
| number
| boolean
| Schema.JsonArray
| Schema.JsonObject
| null
Recursive TypeScript type for any valid immutable JSON value: null,
number, boolean, string, a readonly array of Json values, or a
readonly record of string → Json. For the corresponding schema, see the
Json
const.
Schema that accepts and validates any immutable JSON-compatible value.
Example (Validating a JSON value)
import { Schema } from "effect"
const result = Schema.decodeUnknownOption(Schema.Json)({ key: [1, true, null] })
console.log(result._tag) // "Some"
Json> = import SchemaSchema.function toCodecJson<
S extends Constraint
>(schema: S): toCodecJson<S>
Derives a canonical JSON codec from a schema. The encoded form is Json, and
decoding produces the schema's Type.
toCodecJson(const $Document: Schema.Struct<{
readonly representation: $Representation
readonly references: Schema.$Record<
Schema.String,
$Representation
>
}>
const $Document: {
Type: Struct.Type<Fields>;
Encoded: Struct.Encoded<Fields>;
DecodingServices: Struct.DecodingServices<Fields>;
EncodingServices: Struct.EncodingServices<Fields>;
Iso: Struct.Iso<Fields>;
fields: Fields;
mapFields: (f: (fields: { readonly representation: $Representation; readonly references: Schema.$Record<Schema.String, $Representation> }) => To, options?: { readonly unsafePreserveChecks?: boolean | undefined } | undefined) => Schema.Struct<{ [K in …;
Rebuild: Rebuild;
ast: Ast;
annotate: (annotations: Schema.Annotations.Bottom<Schema.Struct.ReadonlySide<{ readonly representation: $Representation; readonly references: Schema.$Record<Schema.String, $Representation>; }, 'Type'>, readonly []>) => Schema.Struct<{ readonly repre…;
annotateKey: (annotations: Schema.Annotations.Key<Schema.Struct.ReadonlySide<{ readonly representation: $Representation; readonly references: Schema.$Record<Schema.String, $Representation> }, 'Type'>>) => Schema.Struct<{ readonly representation: $Repre…;
check: (checks_0: SchemaAST.Check<Schema.Struct.ReadonlySide<{ readonly representation: $Representation; readonly references: Schema.$Record<Schema.String, $Representation> }, 'Type'>>, ...checks: Array<SchemaAST.Check<Schema.Struct.ReadonlySide<…;
rebuild: (ast: SchemaAST.Objects) => Schema.Struct<{ readonly representation: $Representation; readonly references: Schema.$Record<Schema.String, $Representation> }>;
make: (input: Struct.ReadonlyMakeIn<{ readonly representation: SchemaRepresentation.$Representation; readonly references: $Record<String, SchemaRepresentation.$Representation> }>, options?: MakeOptions) => Struct.ReadonlySide<{ readonly represen…;
makeOption: (input: Struct.ReadonlyMakeIn<{ readonly representation: SchemaRepresentation.$Representation; readonly references: $Record<String, SchemaRepresentation.$Representation> }>, options?: MakeOptions) => Option_.Option<Struct.ReadonlySide<{ re…;
makeEffect: (input: Struct.ReadonlyMakeIn<{ readonly representation: SchemaRepresentation.$Representation; readonly references: $Record<String, SchemaRepresentation.$Representation> }>, options?: MakeOptions) => Effect.Effect<Struct.ReadonlySide<{ rea…;
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; <…;
}
Schema for
Document
.
When to use
Use to validate or serialize a single schema representation document with
Schema.decodeUnknownSync or Schema.encodeSync.
Gotchas
This codec validates document structure but does not resolve $ref keys
against references.
$Document)