glendix/js/json

Serializes gleam/json values and parses JSON into caller-selected types.

Types

Describes why JSON text could not be parsed into the requested type.

pub type JsonError {
  InvalidSyntax(reason: JsonSyntaxError)
  DecoderMismatch(errors: List(decode.DecodeError))
}

Constructors

  • InvalidSyntax(reason: JsonSyntaxError)

    The input is not syntactically valid JSON.

  • DecoderMismatch(errors: List(decode.DecodeError))

    The JSON value does not match the requested decoder.

Describes a deterministic JSON syntax failure.

pub type JsonSyntaxError {
  UnexpectedEndOfInput
  UnexpectedByte(byte: String)
  UnexpectedSequence(sequence: String)
}

Constructors

  • UnexpectedEndOfInput

    The input ended before the JSON value was complete.

  • UnexpectedByte(byte: String)

    The parser encountered an invalid byte.

  • UnexpectedSequence(sequence: String)

    The parser encountered an invalid sequence.

Values

pub fn parse(
  from source: String,
  using decoder: decode.Decoder(value),
) -> Result(value, JsonError)

Parses JSON text with an explicit decoder for the expected result type.

Before Glendix 6, this function returned an untyped json.Json value. Callers now provide a decoder so invalid value shapes fail at this boundary.

pub fn stringify(value value: json.Json) -> String

Serializes a JSON value.

Search Document