json_tag

Types

Function signature for encoding a tagged JSON object.

pub type TagEncoder =
  fn(String, List(#(String, json.Json))) -> json.Json

Values

pub fn decode(
  from json: dynamic.Dynamic,
) -> Result(#(String, dynamic.Dynamic), List(decode.DecodeError))

Decodes a tagged JSON dynamic value, extracting the #type tag and returning the tag value with the original dynamic for further field decoding.

pub fn encode(
  tag tag: String,
  fields fields: List(#(String, json.Json)),
) -> json.Json

Encodes a tagged JSON object with #type set to the given tag.

encode(tag: "Circle", fields: [#("radius", json.float(4.0))])
|> json.to_string()
// {"#type":"Circle","radius":4.0}
pub fn tag_of(
  from json: dynamic.Dynamic,
) -> Result(String, List(decode.DecodeError))

Extracts just the #type tag value from a dynamic JSON value.

pub const type_field: String

The discriminator property name used by JSON Tag.

Search Document