Skip to content

Std.Json

error SyntaxError(message: String, offset: Int)

offset counts code points from the start of the input.

  • message: String
  • offset: Int
fn parse(s: String) -> Dynamic fails SyntaxError

Reads one JSON value, with whitespace allowed around it. For a repeated key in an object, the later value is kept.

fn to_string(value: Dynamic) -> String

The JSON text of value, without whitespace. Keys come in the order of the Map. A string escapes ", \ and the control characters, and keeps every other character as it is. JSON has no bytes, so Binary is written as a string of Bytes.to_base64 (RFC 4648 section 4). parse never gives Binary: that string is read back as Text, and Bytes.from_base64 turns it into the bytes.

fn decode[A: Decode](text: String) -> A fails DecodeError | SyntaxError

parse, then Decode.from_dynamic.

fn decode_all[A: Decode](text: String) -> A fails DecodeErrors | SyntaxError

parse, then Decode.from_dynamic_all.

fn encode[A: Encode](value: A) -> String

Encode.to_dynamic, then to_string.