slackline/value

Free-form json values.

Slack sends free-form json in many places: message metadata, workflow step outputs, datastore items, and any event or block that slackline does not know yet. Value holds that data. You can pattern match on it, encode it again, or run your own decoders on it.

let payload =
  value.Object([
    #("id", value.String("11223")),
    #("title", value.String("Redesign Homepage")),
  ])

Types

pub type Value {
  Null
  Bool(Bool)
  Int(Int)
  Float(Float)
  String(String)
  Array(List(Value))
  Object(List(#(String, Value)))
}

Constructors

  • Null
  • Bool(Bool)
  • Int(Int)
  • Float(Float)
  • String(String)
  • Array(List(Value))
  • Object(List(#(String, Value)))

Values

pub fn at(value: Value, path: List(String)) -> Result(Value, Nil)

Follows a path of object keys.

pub fn decode(
  value: Value,
  decoder: decode.Decoder(a),
) -> Result(a, List(decode.DecodeError))

Runs a decoder on a Value, for example on an unknown event or block:

case event {
  event.UnknownEvent(type_: "my_custom_event", raw:) ->
    value.decode(raw, my_event_decoder())
  _ -> todo
}
pub fn decoder() -> decode.Decoder(Value)

Decodes any json into a Value.

pub fn field(value: Value, key: String) -> Result(Value, Nil)

Looks up a key in an object.

pub fn parse(text: String) -> Result(Value, json.DecodeError)

Parses a json string into a Value.

pub fn string_field(
  value: Value,
  key: String,
) -> Result(String, Nil)

Looks up a string in an object.

pub fn to_dynamic(value: Value) -> dynamic.Dynamic

Converts a Value to Dynamic so it can be fed to a decoder.

pub fn to_json(value: Value) -> json.Json

Encodes a Value as json.

pub fn to_string(value: Value) -> String

Renders a Value as a json string.

✨ Search Document