gossamer/json

A transparent Json type for inspecting or pattern-matching on JSON of unknown structure. For typed encode/decode pipelines, use gleam_json.

Types

A JSON value.

pub type Json {
  Null
  Boolean(Bool)
  Number(Float)
  String(String)
  Array(List(Json))
  Object(dict.Dict(String, Json))
}

Constructors

  • Null

    The JSON null literal.

  • Boolean(Bool)

    A JSON boolean — true or false.

  • Number(Float)

    A JSON number. JSON has no distinction between integers and floats; all numeric values are decoded as Float.

  • String(String)

    A JSON string.

  • Array(List(Json))

    A JSON array — an ordered sequence of values.

  • Object(dict.Dict(String, Json))

    A JSON object — a string-keyed map of values.

Values

pub fn parse(text: String) -> Result(Json, Nil)

Parses a JSON string into a Json value. Returns an error if the string is not valid JSON per the ECMA-404 grammar. Equivalent to JavaScript’s JSON.parse.

pub fn stringify(json: Json) -> String

Serializes a Json value into a JSON string. Equivalent to JavaScript’s JSON.stringify.

Search Document