sparkling/decode
Values
pub fn decode_json(
json_string: String,
decoder: decode.Decoder(a),
) -> Result(a, json.DecodeError)
Decode a single JSON string into a value of type a using the provided decoder.
pub fn decode_json_each_row(
json_each_row: String,
decoder: decode.Decoder(a),
) -> Result(List(a), String)
Decode JSONEachRow format (newline-separated JSON objects) into a list of values. Each line is parsed independently and decoded using the provided decoder. Error messages include line index and excerpt (first 100 chars) for large lines.
pub fn decode_json_each_row_dict(
json_each_row: String,
) -> Result(List(dict.Dict(String, json.Json)), String)
Decode JSONEachRow as list of dictionaries (for dynamic access without custom decoder). Useful for tools, debugging, or when schema is not known upfront.
pub fn decode_json_each_row_raw(
json_each_row: String,
) -> Result(List(json.Json), String)
Decode JSONEachRow format into raw JSON values (List(json.Json)). Useful for debugging, tools, and cases where you don’t have a specific decoder. Each line is parsed as json.Json without further type conversion.
pub fn decode_json_each_row_streaming(
json_each_row: String,
decoder: decode.Decoder(a),
callback: fn(a) -> Nil,
) -> Result(Int, String)
Streaming decoder for JSONEachRow format - processes lines lazily. Calls the callback function for each successfully decoded line. Returns the count of successfully processed lines or an error.
This is memory-efficient for large responses as it doesn’t load all data into a list.
Example moved to: docs/examples/decode_examples.md