neco_gleam/json
Types
pub type Failure {
Invalid(offset: Int, message: String)
InvalidUtf8(offset: Int)
UnexpectedEnd(offset: Int)
Trailing(offset: Int)
DuplicateKey(offset: Int, key: String)
EncodeDuplicateKey(key: String)
}
Constructors
-
Invalid(offset: Int, message: String) -
InvalidUtf8(offset: Int) -
UnexpectedEnd(offset: Int) -
Trailing(offset: Int) -
DuplicateKey(offset: Int, key: String) -
EncodeDuplicateKey(key: String)
Values
pub fn canonicalize(value: Value) -> Value
Recursively orders object fields by Unicode scalar value while preserving array order, number tokens, and duplicate fields.
pub fn decode(bytes: BitArray) -> Result(Value, Failure)
Decodes one JSON value from UTF-8 bytes. JSON whitespace may surround the
value, while trailing non-whitespace bytes produce Trailing. Other typed
failures cover invalid UTF-8, invalid JSON, duplicate keys, and nesting at
the parser limit.
pub fn encode(value: Value) -> Result(BitArray, Failure)
Encodes the UTF-8 bytes of encode_text with the same failure values.
pub fn encode_text(value: Value) -> Result(String, Failure)
Encodes deterministic JSON text after ordering object fields. Duplicate
object keys produce EncodeDuplicateKey.
pub fn number_from_int(value: Int) -> Number
Uses the decimal integer spelling as a JSON number token.
pub fn number_from_string(text: String) -> Result(Number, Nil)
Preserves text when it follows the JSON number grammar, with
Error(Nil) for other strings.