Std. Json
(Cure Standard Library v0.37.2)
View Source
Exact, typed JSON for Cure.
JSON numbers retain their lexical category and normalized exact spelling. Decoding a number into an application type is performed by that type's literal protocol implementation; the JSON layer never routes through Float.
Examples
use Std.Json
to_json(42) # => "42"
encode(Object([member("ok", Boolean(true))]))
decode("{\"ok\":true}")
Summary
Callbacks
Conversion is deliberately split at the structured Value boundary. Derivation constructs/consumes Values and therefore cannot accidentally double-encode a field or smuggle host JSON semantics into the result.
Functions
Parse a JSON string into a structured Value, rejecting invalid syntax or
trailing tokens.
Parse a JSON string and decode it into any target type implementing FromJSON.
Render the structured tree entirely in Cure. Only principled character and numeric primitives used by the wider stdlib remain across the extern edge.
Construct an ObjectMember pairing a string key with a JSON Value.
Look up key in a list of object members, returning Error(UnexpectedValue(_))
when the key is missing.
Serialize any value implementing ToJSON directly to a JSON string.
Types
enum DecodeError
InvalidSyntax
UnexpectedValue
InvalidNumber
enum Number
NaturalNumber
IntegerNumber
DecimalNumber
struct NumberScan
?
?
?
?
struct ObjectMember
?
?
enum ParseResult
Parsed
ParseFailure
enum Value
Null
Boolean
Number
String
Array
Object
Callbacks
Functions
fn append_code_point(value: Int, rest: List(Char), reversed: List(Char)) -> ParseResult(Value)
fn decode(source: String) -> Result(Value, DecodeError)
Parse a JSON string into a structured Value, rejecting invalid syntax or
trailing tokens.
fn decode_as(source: String) -> Result(t, DecodeError)
Parse a JSON string and decode it into any target type implementing FromJSON.
fn digit_1_to_9(char: Char) -> Bool
fn encode(value: Value) -> String
Render the structured tree entirely in Cure. Only principled character and numeric primitives used by the wider stdlib remain across the extern edge.
fn escape(text: String) -> String
fn escape_reversed(text: List(Char), output: List(Char)) -> List(Char)
fn finish_exponent_digits(source: List(Char), reversed: List(Char), negative: Bool) -> ParseResult(NumberScan)
fn four_hex(source: List(Char)) -> ParseResult(Int)
fn from_json_value(value: Value) -> Result(t, DecodeError)
fn hex_digit(value: Int) -> Char
fn hex_value(char: Char) -> Result(Int, DecodeError)
fn hex_values(chars: List(Char)) -> Result(List(Int), DecodeError)
fn is_digit(char: Char) -> Bool
fn is_number_start(char: Char) -> Bool
fn literal_float_decimal(literal: DecimalLiteral) -> Result(Float, DecodeError)
fn literal_float_integer(literal: IntegerLiteral) -> Result(Float, DecodeError)
fn literal_float_natural(literal: NaturalLiteral) -> Result(Float, DecodeError)
fn member(key: String, value: Value) -> ObjectMember
Construct an ObjectMember pairing a string key with a JSON Value.
fn parse_array(source: List(Char), reversed: List(Value)) -> ParseResult(Value)
fn parse_array_separator(source: List(Char), reversed: List(Value)) -> ParseResult(Value)
fn parse_array_value(source: List(Char), reversed: List(Value)) -> ParseResult(Value)
fn parse_escape(source: List(Char), reversed: List(Char)) -> ParseResult(Value)
fn parse_keyword(source: List(Char), wanted: List(Char), value: Value) -> ParseResult(Value)
fn parse_low_surrogate(high: Int, source: List(Char), reversed: List(Char)) -> ParseResult(Value)
fn parse_member_colon(key: String, source: List(Char), reversed: List(ObjectMember)) -> ParseResult(Value)
fn parse_number(source: List(Char)) -> ParseResult(Value)
fn parse_object(source: List(Char), reversed: List(ObjectMember)) -> ParseResult(Value)
fn parse_object_member(source: List(Char), reversed: List(ObjectMember)) -> ParseResult(Value)
fn parse_object_separator(source: List(Char), reversed: List(ObjectMember)) -> ParseResult(Value)
fn parse_string(source: List(Char), reversed: List(Char)) -> ParseResult(Value)
fn parse_unicode_escape(source: List(Char), reversed: List(Char)) -> ParseResult(Value)
fn parse_value(source: List(Char)) -> ParseResult(Value)
fn prepend_escape(char: Char, output: List(Char)) -> List(Char)
fn prepend_unicode_control(point: Int, output: List(Char)) -> List(Char)
fn render_member(entry: ObjectMember) -> String
fn render_members(members: List(ObjectMember)) -> String
fn render_number(number: Number) -> String
fn render_value(value: Value) -> String
fn render_values(values: List(Value)) -> String
fn required_member(key: String, members: List(ObjectMember)) -> Result(Value, DecodeError)
Look up key in a list of object members, returning Error(UnexpectedValue(_))
when the key is missing.
fn scan_digits(source: List(Char), reversed: List(Char)) -> Tuple(List(Char), List(Char))
fn scan_exponent(source: List(Char), reversed: List(Char), negative: Bool) -> ParseResult(NumberScan)
fn scan_exponent_digits(source: List(Char), reversed: List(Char), negative: Bool) -> ParseResult(NumberScan)
fn scan_fraction_or_exponent(source: List(Char), reversed: List(Char), negative: Bool, decimal: Bool) -> ParseResult(NumberScan)
fn scan_integer_part(source: List(Char), reversed: List(Char), negative: Bool) -> ParseResult(NumberScan)
fn scan_number(source: List(Char)) -> ParseResult(NumberScan)
fn skip_space(source: List(Char)) -> List(Char)
fn to_json(value: t) -> String
Serialize any value implementing ToJSON directly to a JSON string.
fn to_json_value(value: t) -> Value