Skip to content

pactl: fix invalid JSON output by overriding LC_NUMERIC

Olivier Gayot requested to merge ogayot/pulseaudio:pactl-json-locale into master


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:


Fixed by overriding the LC_NUMERIC value when we request JSON output.

Thanks! Olivier

Edited by Olivier Gayot

Merge request reports