lvm --reportformat json_std generates invalid JSON for percentages in locales with radix character = ","
Using --reportformat json_std
leads to invalid JSON when the locale specifies "," (comma) as the radix character (e.g. de_DE, nl_NL, etc.):
# LANG=en_GB.UTF-8 lvs --report-format json_std -o data_percent fedora/home
{
"report": [
{
"lv": [
{"data_percent":11.49}
]
}
]
,
"log": [
]
}
Vs.:
# LANG=de_DE.UTF-8 lvs --report-format json_std -o data_percent fedora/home
{
"report": [
{
"lv": [
{"data_percent":11,49}
]
}
]
,
"log": [
]
}
The latter is not syntactically valid JSON, since ,
(0x2C) is the value-separator, and numbers require the decimal-point to be "." (0x2E):
https://www.rfc-editor.org/rfc/rfc7158#section-6
Common parsers are unable to parse the resulting strings:
# LANG=de_DE.UTF-8 lvs --report-format json_std -o data_percent fedora/home | python3 -c "import sys; from json import loads; loads(sys.stdin.read())"
Traceback (most recent call last):
File "<string>", line 1, in <module>
import sys; from json import loads; loads(sys.stdin.read())
~~~~~^^^^^^^^^^^^^^^^^^
File "/usr/lib64/python3.13/json/__init__.py", line 346, in loads
return _default_decoder.decode(s)
~~~~~~~~~~~~~~~~~~~~~~~^^^
File "/usr/lib64/python3.13/json/decoder.py", line 345, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib64/python3.13/json/decoder.py", line 361, in raw_decode
obj, end = self.scan_once(s, idx)
~~~~~~~~~~~~~~^^^^^^^^
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 5 column 38 (char 93)
This isn't an issue for --reportformat json
, since the offending value is encoded as a quoted string in _output_field_json_fmt()
. With json_std
the percent field is treated as a pure numeric field and encoded as a JSON number using dm_report_field_percent()
.