diff --git a/vlib/x/json2/encoder.v b/vlib/x/json2/encoder.v index 48363bcf6c27f9..1f833b3ac27b94 100644 --- a/vlib/x/json2/encoder.v +++ b/vlib/x/json2/encoder.v @@ -117,7 +117,11 @@ fn (e &Encoder) encode_any(val Any, level int, mut wr io.Writer) ! { e.encode_newline(level - 1, mut wr)! wr.write([u8(`]`)])! } - time.Time {} + time.Time { + wr.write(json2.quote_bytes)! + wr.write(val.format_rfc3339().bytes())! + wr.write(json2.quote_bytes)! + } Null { wr.write(json2.null_in_bytes)! } diff --git a/vlib/x/json2/encoder_test.v b/vlib/x/json2/encoder_test.v index f91a06212c8e14..d05eb6f9920a5b 100644 --- a/vlib/x/json2/encoder_test.v +++ b/vlib/x/json2/encoder_test.v @@ -1,5 +1,6 @@ import x.json2 as json import strings +import time struct StructType[T] { mut: @@ -136,3 +137,9 @@ fn test_encode_simple() { assert json.encode('hello!') == '"hello!"' assert json.encode(1) == '1' } + +fn test_encode_time() { + assert json.encode({ + 'bro': json.Any(time.Time{}) + }) == '{"bro":"0000-00-00T00:00:00.000Z"}' +}