<E extends string>(): Getter<Schema.MutableJson, E>
<E extends string>(options: ParseJsonOptions): Getter<unknown, E>Parses a JSON string into a value.
When to use
Use when you need a schema getter to parse a present encoded JSON string during decoding.
Details
- Skips
Noneinputs. - Without
reviver: returnsSchema.MutableJson(typed JSON). - With
reviver: returnsunknown(reviver may produce arbitrary values). - On parse failure, fails with
SchemaIssue.InvalidValuecontaining the error message.
Example (Parsing JSON)
import { SchemaGetter } from "effect"
const parse = SchemaGetter.parseJson<string>()
// Getter<MutableJson, string>export function function parseJson<E extends string>(): Getter<Schema.MutableJson, E> (+1 overload)Parses a JSON string into a value.
When to use
Use when you need a schema getter to parse a present encoded JSON string
during decoding.
Details
- Skips
None inputs.
- Without
reviver: returns Schema.MutableJson (typed JSON).
- With
reviver: returns unknown (reviver may produce arbitrary values).
- On parse failure, fails with
SchemaIssue.InvalidValue containing the error message.
Example (Parsing JSON)
import { SchemaGetter } from "effect"
const parse = SchemaGetter.parseJson<string>()
// Getter<MutableJson, string>
parseJson<function (type parameter) E in parseJson<E extends string>(): Getter<Schema.MutableJson, E>E extends string>(): class Getter<out T, in E, R = never>class Getter {
run: (input: Option.Option<E>, options: SchemaAST.ParseOptions) => Effect.Effect<Option.Option<T>, SchemaIssue.Issue, R>;
map: <T2>(f: (t: T) => T2) => Getter<T2, E, R>;
compose: <T2, R2>(other: Getter<T2, T, R2>) => Getter<T2, E, R | R2>;
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; <…;
}
Represents a composable transformation from an encoded type E to a decoded type T.
When to use
Use when you need a schema getter to build and compose custom transformations
for Schema.decodeTo or Schema.decode.
Details
A getter wraps a function Option<E> -> Effect<Option<T>, Issue, R>. It
receives Option.None when the encoded key is absent, such as a missing
struct field, and returns Option.None to omit the value from the decoded
output. It fails with Issue on invalid input and may require Effect
services via R. .map(f) applies f to the decoded value inside Some
while leaving None unchanged. .compose(other) chains two getters by
feeding the output of this into other; passthrough getters on either side
are optimized away.
Example (Creating and composing getters)
import { SchemaGetter } from "effect"
const parseNumber = SchemaGetter.transform<number, string>((s) => Number(s))
const double = SchemaGetter.transform<number, number>((n) => n * 2)
const composed = parseNumber.compose(double)
// composed: Getter<number, string> — parses then doubles
Getter<import SchemaSchema.type Schema.MutableJson = /*unresolved*/ anyMutableJson, function (type parameter) E in parseJson<E extends string>(): Getter<Schema.MutableJson, E>E>
export function function parseJson<E extends string>(options: ParseJsonOptions): Getter<unknown, E> (+1 overload)Parses a JSON string into a value.
When to use
Use when you need a schema getter to parse a present encoded JSON string
during decoding.
Details
- Skips
None inputs.
- Without
reviver: returns Schema.MutableJson (typed JSON).
- With
reviver: returns unknown (reviver may produce arbitrary values).
- On parse failure, fails with
SchemaIssue.InvalidValue containing the error message.
Example (Parsing JSON)
import { SchemaGetter } from "effect"
const parse = SchemaGetter.parseJson<string>()
// Getter<MutableJson, string>
parseJson<function (type parameter) E in parseJson<E extends string>(options: ParseJsonOptions): Getter<unknown, E>E extends string>(options: ParseJsonOptions(parameter) options: {
reviver: Parameters<typeof JSON.parse>[1];
}
options: type ParseJsonOptions = {
readonly reviver?: Parameters<
typeof JSON.parse
>[1]
}
ParseJsonOptions): class Getter<out T, in E, R = never>class Getter {
run: (input: Option.Option<E>, options: SchemaAST.ParseOptions) => Effect.Effect<Option.Option<T>, SchemaIssue.Issue, R>;
map: <T2>(f: (t: T) => T2) => Getter<T2, E, R>;
compose: <T2, R2>(other: Getter<T2, T, R2>) => Getter<T2, E, R | R2>;
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; <…;
}
Represents a composable transformation from an encoded type E to a decoded type T.
When to use
Use when you need a schema getter to build and compose custom transformations
for Schema.decodeTo or Schema.decode.
Details
A getter wraps a function Option<E> -> Effect<Option<T>, Issue, R>. It
receives Option.None when the encoded key is absent, such as a missing
struct field, and returns Option.None to omit the value from the decoded
output. It fails with Issue on invalid input and may require Effect
services via R. .map(f) applies f to the decoded value inside Some
while leaving None unchanged. .compose(other) chains two getters by
feeding the output of this into other; passthrough getters on either side
are optimized away.
Example (Creating and composing getters)
import { SchemaGetter } from "effect"
const parseNumber = SchemaGetter.transform<number, string>((s) => Number(s))
const double = SchemaGetter.transform<number, number>((n) => n * 2)
const composed = parseNumber.compose(double)
// composed: Getter<number, string> — parses then doubles
Getter<unknown, function (type parameter) E in parseJson<E extends string>(options: ParseJsonOptions): Getter<unknown, E>E>
export function function parseJson<E extends string>(): Getter<Schema.MutableJson, E> (+1 overload)Parses a JSON string into a value.
When to use
Use when you need a schema getter to parse a present encoded JSON string
during decoding.
Details
- Skips
None inputs.
- Without
reviver: returns Schema.MutableJson (typed JSON).
- With
reviver: returns unknown (reviver may produce arbitrary values).
- On parse failure, fails with
SchemaIssue.InvalidValue containing the error message.
Example (Parsing JSON)
import { SchemaGetter } from "effect"
const parse = SchemaGetter.parseJson<string>()
// Getter<MutableJson, string>
parseJson<function (type parameter) E in parseJson<E extends string>(options?: ParseJsonOptions | undefined): Getter<unknown, E>E extends string>(options: ParseJsonOptions | undefinedoptions?: type ParseJsonOptions = {
readonly reviver?: Parameters<
typeof JSON.parse
>[1]
}
ParseJsonOptions | undefined): class Getter<out T, in E, R = never>class Getter {
run: (input: Option.Option<E>, options: SchemaAST.ParseOptions) => Effect.Effect<Option.Option<T>, SchemaIssue.Issue, R>;
map: <T2>(f: (t: T) => T2) => Getter<T2, E, R>;
compose: <T2, R2>(other: Getter<T2, T, R2>) => Getter<T2, E, R | R2>;
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; <…;
}
Represents a composable transformation from an encoded type E to a decoded type T.
When to use
Use when you need a schema getter to build and compose custom transformations
for Schema.decodeTo or Schema.decode.
Details
A getter wraps a function Option<E> -> Effect<Option<T>, Issue, R>. It
receives Option.None when the encoded key is absent, such as a missing
struct field, and returns Option.None to omit the value from the decoded
output. It fails with Issue on invalid input and may require Effect
services via R. .map(f) applies f to the decoded value inside Some
while leaving None unchanged. .compose(other) chains two getters by
feeding the output of this into other; passthrough getters on either side
are optimized away.
Example (Creating and composing getters)
import { SchemaGetter } from "effect"
const parseNumber = SchemaGetter.transform<number, string>((s) => Number(s))
const double = SchemaGetter.transform<number, number>((n) => n * 2)
const composed = parseNumber.compose(double)
// composed: Getter<number, string> — parses then doubles
Getter<unknown, function (type parameter) E in parseJson<E extends string>(options?: ParseJsonOptions | undefined): Getter<unknown, E>E> {
return function onSome<T, E, R = never>(
f: (
e: E,
options: SchemaAST.ParseOptions
) => Effect.Effect<
Option.Option<T>,
SchemaIssue.Issue,
R
>
): Getter<T, E, R>
Creates a getter that handles present values (Option.Some), passing None through.
When to use
Use when you need a schema getter to transform or validate only when a field
value is present.
- Missing keys should remain absent in the output.
Details
- When input is
None, returns None (no-op).
- When input is
Some(e), calls f(e, options) to produce the result.
f may return None to omit the value, or fail with an Issue.
Example (Transforming only present values)
import { Effect, Option, SchemaGetter } from "effect"
const parseIfPresent = SchemaGetter.onSome<number, string>(
(s) => Effect.succeed(Option.some(Number(s)))
)
onSome((input: E extends stringinput) =>
import EffectEffect.try({
try: () => anytry: () => import OptionOption.some(var JSON: JSONAn intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format.
JSON.JSON.parse(text: string, reviver?: (this: any, key: string, value: any) => any): anyConverts a JavaScript Object Notation (JSON) string into an object.
parse(input: E extends stringinput, options: ParseJsonOptions | undefinedoptions?.reviver?: | ((this: any, key: string, value: any) => any)
| undefined
reviver)),
catch: (e: any) => SchemaIssue.InvalidValuecatch: (e: anye) => new import SchemaIssueSchemaIssue.constructor InvalidValue(actual: Option.Option<unknown>, annotations?: Schema.Annotations.Issue | undefined): SchemaIssue.InvalidValueRepresents a schema issue produced when the input has the correct type but its value violates a
constraint (e.g. a string that is too short, a number out of range).
When to use
Use when you need to detect constraint violations from Schema.filter,
Schema.minLength, Schema.greaterThan, or similar checks.
Details
actual is Option.some(value) when the failing value is known, or
Option.none() when absent.
annotations optionally carries a message string for formatting.
- The default formatter renders this as
"Invalid data <actual>" unless a
custom message annotation is provided.
Example (Returning InvalidValue from a custom filter)
import { Option, SchemaIssue } from "effect"
const issue = new SchemaIssue.InvalidValue(
Option.some(""),
{ message: "must not be empty" }
)
console.log(String(issue))
// "must not be empty"
InvalidValue(import OptionOption.some(input: E extends stringinput), { message: stringmessage: module globalThisglobalThis.var String: StringConstructor
;(value?: any) => string
Allows manipulation and formatting of text strings and determination and location of substrings within strings.
String(e: anye) })
})
)
}