Skip to Content
i documentation
Standard library referenceModules

std/schema

Composable two-way JSON codecs.

Schema

Schema(A, E) = (read = (json.Json) -> Result(A, E), write = (A) -> json.Json)

SchemaError

SchemaError = (path = List(Path), expected = String)

Path

Path = Field | Index

ParseError

ParseError = Syntax | Decode

decode

decode = <A, E>(schema : Schema(A, E), value : json.Json) -> Result(A, E) {

encode

encode = <A, E>(schema : Schema(A, E), value : A) -> json.Json {

parse

parse = <A>(schema : Schema(A, SchemaError), text : String) -> Result(

print

print = <A, E>(schema : Schema(A, E), value : A) -> String {

int

int = Schema(

float

float = Schema(

string

string = Schema(

bool

bool = Schema(

null

null = Schema(

literal_string

literal_string = <K>(value : K) -> Schema(K, SchemaError) {

literal_int

literal_int = <K>(value : K) -> Schema(K, SchemaError) {

optional

optional = nullable

nullable

nullable = <A>(s : Schema(A, SchemaError)) -> Schema(Option(A), SchemaError) {

list

list = <A>(s : Schema(A, SchemaError)) -> Schema(List(A), SchemaError) {

dict

dict = <A>(s : Schema(A, SchemaError)) -> Schema(

tuple

tuple = <A, B>(

object

object = <A>(empty : A) -> Schema(A, SchemaError) {

field

field = <A, V>(

optional_field

optional_field = <A, V>(

union

union = <A>(

tagged_union

tagged_union = <A>(

map

map = <A, B>(

transform

transform = map

refine

refine = <A>(

lazy

lazy = <A>(get : () -> Schema(A, SchemaError)) -> Schema(A, SchemaError) {