misc/json: don't wrap top-level pretty strings/infs in quotes

This makes pretty-printing nodes substantially more friendly.
This commit is contained in:
rcombs 2022-12-15 19:16:57 -06:00
parent 91ba71b09f
commit fa7202d9f2
1 changed files with 5 additions and 2 deletions

View File

@ -300,12 +300,15 @@ static int json_append(bstr *b, const struct mpv_node *src, int indent)
bstr_xappend_asprintf(NULL, b, "%"PRId64, src->u.int64); bstr_xappend_asprintf(NULL, b, "%"PRId64, src->u.int64);
return 0; return 0;
case MPV_FORMAT_DOUBLE: { case MPV_FORMAT_DOUBLE: {
const char *px = isfinite(src->u.double_) ? "" : "\""; const char *px = (isfinite(src->u.double_) || indent == 0) ? "" : "\"";
bstr_xappend_asprintf(NULL, b, "%s%f%s", px, src->u.double_, px); bstr_xappend_asprintf(NULL, b, "%s%f%s", px, src->u.double_, px);
return 0; return 0;
} }
case MPV_FORMAT_STRING: case MPV_FORMAT_STRING:
write_json_str(b, src->u.string); if (indent == 0)
APPEND(b, src->u.string);
else
write_json_str(b, src->u.string);
return 0; return 0;
case MPV_FORMAT_NODE_ARRAY: case MPV_FORMAT_NODE_ARRAY:
case MPV_FORMAT_NODE_MAP: { case MPV_FORMAT_NODE_MAP: {