mirror of
https://github.com/lm-sensors/lm-sensors.git
synced 2026-11-27 20:48:22 +00:00
sensors: Handle json trailing ',' when no features are listed
The json format requires that the last entry of a dictionary does not
have a trailing ','. To avoid generating invalid json output, check that
there are features to list before emitting the trailing ','.
This issue is present when a chip exists but all its sensors are
ignored:
{
"example-device" : {
"Adapter": "example adapter",
}
}
The corrected output is:
{
"example-device" : {
"Adapter": "example adapter"
}
}
Signed-off-by: Nathan Rossi <nathan.rossi@digi.com>
This commit is contained in:
1 parent
31d1f125d8
commit
c567724339
1 file changed
+11
-3
+11
-3
@@ -178,11 +178,19 @@ static void do_a_json_print(const sensors_chip_name *name)
|
||||
{
|
||||
printf(" \"%s\":{\n", sprintf_chip_name(name));
|
||||
if (!hide_adapter) {
|
||||
int a = 0;
|
||||
const char *adap = sensors_get_adapter_name(&name->bus);
|
||||
if (adap)
|
||||
printf(" \"Adapter\": \"%s\",\n", adap);
|
||||
else
|
||||
if (adap) {
|
||||
printf(" \"Adapter\": \"%s\"", adap);
|
||||
/* only print trailing ',' if there are features to list */
|
||||
if (sensors_get_features(name, &a) != NULL) {
|
||||
printf(",\n");
|
||||
} else {
|
||||
printf("\n");
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "Can't get adapter name\n");
|
||||
}
|
||||
}
|
||||
print_chip_json(name);
|
||||
printf(" }");
|
||||
|
||||
Reference in new issue
Block a user