diff --git a/vlib/x/json2/encoder.v b/vlib/x/json2/encoder.v index d62387fb3a..ee8f0b7c0a 100644 --- a/vlib/x/json2/encoder.v +++ b/vlib/x/json2/encoder.v @@ -69,10 +69,7 @@ pub fn (f Any) json_str() string { string { return json_string(f) } - int { - return f.str() - } - u64, i64 { + bool, int, u64, i64 { return f.str() } f32 { @@ -89,9 +86,6 @@ pub fn (f Any) json_str() string { } return str_f64 } - bool { - return f.str() - } map[string]Any { return f.str() } diff --git a/vlib/x/json2/encoder_test.v b/vlib/x/json2/encoder_test.v index ea7807df9f..02ba71ef00 100644 --- a/vlib/x/json2/encoder_test.v +++ b/vlib/x/json2/encoder_test.v @@ -15,6 +15,14 @@ fn test_json_escape_low_chars() { fn test_json_string() { text := json2.Any('te✔st') assert text.json_str() == r'te\u2714st' + boolean := json2.Any(true) + assert boolean.json_str() == 'true' + integer := json2.Any(int(-5)) + assert integer.json_str() == '-5' + u64integer := json2.Any(u64(5000)) + assert u64integer.json_str() == '5000' + i64integer := json2.Any(i64(-17)) + assert i64integer.json_str() == '-17' } fn test_json_string_emoji() {