1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

x.json2: add customized JSON output capability via Encoder (#13654)

This commit is contained in:
Ned
2022-03-04 19:39:23 +08:00
committed by GitHub
parent 74d5106e8f
commit 437fa02f27
6 changed files with 275 additions and 168 deletions

View File

@@ -27,19 +27,16 @@ fn any_to_json(a toml.Any) string {
return 'null'
}
toml.DateTime {
json_text := json2.Any(a.str())
return '"$json_text.json_str()"'
return json2.Any(a.str()).json_str()
}
toml.Date {
json_text := json2.Any(a.str())
return '"$json_text.json_str()"'
return json2.Any(a.str()).json_str()
}
toml.Time {
json_text := json2.Any(a.str())
return '"$json_text.json_str()"'
return json2.Any(a.str()).json_str()
}
string {
return '"' + json2.Any(a.str()).json_str() + '"'
return json2.Any(a.str()).json_str()
}
bool {
return json2.Any(bool(a)).json_str()
@@ -63,7 +60,7 @@ fn any_to_json(a toml.Any) string {
mut str := '{'
for key, val in a {
json_key := json2.Any(key)
str += ' "$json_key.json_str()": ${any_to_json(val)},'
str += ' $json_key.json_str(): ${any_to_json(val)},'
}
str = str.trim_right(',')
str += ' }'