mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-30 17:18:21 +03:00
libdm: report: use 'null' for undefined numeric values in JSON_STD output
For JSON_STD format, use 'null' if a field has no value at all. In JSON format, we print undefined numeric values this way: "key" = "" while in JSON_STD format, we print undefined numeric values this way: "key" = null (Keep in mind that 'null' is different from 0 (zero value) which is a defined value.)
This commit is contained in:
parent
99299eb728
commit
1e31621ceb
@ -4360,6 +4360,7 @@ static int _sort_rows(struct dm_report *rh)
|
||||
#define JSON_ARRAY_START "["
|
||||
#define JSON_ARRAY_END "]"
|
||||
#define JSON_ESCAPE_CHAR "\\"
|
||||
#define JSON_NULL "null"
|
||||
|
||||
#define UNABLE_TO_EXTEND_OUTPUT_LINE_MSG "dm_report: Unable to extend output line"
|
||||
|
||||
@ -4449,8 +4450,13 @@ static int _output_field(struct dm_report *rh, struct dm_report_field *field)
|
||||
}
|
||||
}
|
||||
|
||||
repstr = field->report_string;
|
||||
if (_is_json_std_report(rh) && _is_pure_numeric_field(field) && !*field->report_string)
|
||||
repstr = JSON_NULL;
|
||||
else
|
||||
repstr = field->report_string;
|
||||
|
||||
width = field->props->width;
|
||||
|
||||
if (!(rh->flags & DM_REPORT_OUTPUT_ALIGNED)) {
|
||||
if (_is_json_report(rh)) {
|
||||
/* Escape any JSON_QUOTE that may appear in reported string. */
|
||||
|
@ -4359,6 +4359,7 @@ static int _sort_rows(struct dm_report *rh)
|
||||
#define JSON_ARRAY_START "["
|
||||
#define JSON_ARRAY_END "]"
|
||||
#define JSON_ESCAPE_CHAR "\\"
|
||||
#define JSON_NULL "null"
|
||||
|
||||
#define UNABLE_TO_EXTEND_OUTPUT_LINE_MSG "dm_report: Unable to extend output line"
|
||||
|
||||
@ -4448,8 +4449,13 @@ static int _output_field(struct dm_report *rh, struct dm_report_field *field)
|
||||
}
|
||||
}
|
||||
|
||||
repstr = field->report_string;
|
||||
if (_is_json_std_report(rh) && _is_pure_numeric_field(field) && !*field->report_string)
|
||||
repstr = JSON_NULL;
|
||||
else
|
||||
repstr = field->report_string;
|
||||
|
||||
width = field->props->width;
|
||||
|
||||
if (!(rh->flags & DM_REPORT_OUTPUT_ALIGNED)) {
|
||||
if (_is_json_report(rh)) {
|
||||
/* Escape any JSON_QUOTE that may appear in reported string. */
|
||||
|
Loading…
Reference in New Issue
Block a user