From c3c84a3691e700157ccd3c75fdae53c6eec89775 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Mon, 16 May 2022 00:25:43 +0200 Subject: [PATCH] pactl: fix invalid JSON output by overriding LC_NUMERIC When the --format json parameter is given on the command line, we attempt to produce a JSON output for most commands. Our implementation of the JSON serialization uses vsnprintf to output numbers. Unfortunately, vsnprintf is affected by the locale and more specifically the LC_NUMERIC variable. When LC_NUMERIC is set to, for instance, fr_FR.UTF-8, floating-point numbers are output with a comma as the decimal separator, which is then considered invalid JSON. $ LC_NUMERIC=fr_FR.UTF-8 pactl --format json list sinks | jq . parse error: Objects must consist of key:value pairs at line 1, column 435 This is the token which failed to parse: }},"balance":0,00,"base_volume":{ Fixed by overriding the LC_NUMERIC value when we request JSON output. Signed-off-by: Olivier Gayot Part-of: --- src/utils/pactl.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils/pactl.c b/src/utils/pactl.c index 3c1eeb0d0..35163f277 100644 --- a/src/utils/pactl.c +++ b/src/utils/pactl.c @@ -2746,6 +2746,7 @@ int main(int argc, char *argv[]) { format = TEXT; } else if (pa_streq(opt_format, "json")) { format = JSON; + setlocale(LC_NUMERIC, "C"); } else { pa_log(_("Invalid format value '%s'"), opt_format); goto quit;