btrfs-progs: print numeric values unquoted in json

The json spec allows numeric values and it's recommended to use them
instead of the stringified numbers. This is a potentially breaking change
if some tools relied on the string value.

As most formats we now have are '%llu' and it's convenient to just pass
it to vprintf, don't add a special type for ints. Any new int type must
be added to the list.

{
	"number": 1234
}

Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Sterba 2023-08-18 01:24:03 +02:00
parent 155eb56417
commit 25fc470252
1 changed files with 5 additions and 2 deletions

View File

@ -145,7 +145,10 @@ static void fmt_separator(struct format_ctx *fctx)
/* Detect formats or values that must not be quoted (null, bool) */
static bool fmt_set_unquoted(struct format_ctx *fctx, const struct rowspec *row)
{
if (strcmp(row->fmt, "bool") == 0)
static const char *types[] = { "%llu", "bool" };
for (int i = 0; i < sizeof(types) / sizeof(types[0]); i++)
if (strcmp(types[i], row->fmt) == 0)
return true;
return false;
}