Esc

time_json_decode

procedureextensionsince 0.36.1Source
  • macOS: time_json_decode works on macOS
  • Linux: time_json_decode works on Linux
  • Windows: time_json_decode works on Windows
  • Wasm: time_json_decode works on Wasm

Uses Json_Reader. Custom Json field decoder; parse errors become Json INVALID_VALUE and output stays unchanged.

Signature

time_json_decode :: (
    reader: *Json_Reader,
    out: *$T/ .[Date, Time_Of_Day, Date_Time, Timestamp, Signed_Duration, Offset, Time_Zone, Zoned, Span]
) -> bool
Example
#import "Extensions/Json";
T :: #import "Extensions/Time";

Event :: struct {
    day: Date; @json(with=time_json)
    time_json_encode :: T.time_json_encode;
    time_json_decode :: T.time_json_decode;
}

main :: () {
    _, error := from_json(Event, "{\"day\":\"2024-02-30\"}");
    assert(error.kind == .INVALID_VALUE);
}

See also