if (fmt->json_format == UL_JSON_LINE)
s = "{";
else if (fmt->json_format == UL_JSON_COMPACT) {
+ /* At nesting depth 2, put the object opens on a new line
+ * for readability; otherwise keep fully compact (no newline). */
if (fmt->indent == 2)
s = name ? ":{" : "\n{";
else
switch (type) {
case UL_JSON_OBJECT:
- if (fmt->json_format == UL_JSON_LINE)
- s = name ? ":{}" : "{}";
- else if (fmt->json_format == UL_JSON_COMPACT)
- s = name ? ":{}" : "{}";
- else
+ if (fmt->json_format == UL_JSON_PRETTY)
s = name ? ": {}" : "{}";
+ else
+ s = name ? ":{}" : "{}";
break;
case UL_JSON_ARRAY:
- if (fmt->json_format == UL_JSON_LINE)
- s = name ? ":[]" : "[]";
- else if (fmt->json_format == UL_JSON_COMPACT)
- s = name ? ":[]" : "[]";
- else
+ if (fmt->json_format == UL_JSON_PRETTY)
s = name ? ": []" : "[]";
+ else
+ s = name ? ":[]" : "[]";
break;
case UL_JSON_VALUE:
- if (fmt->json_format == UL_JSON_LINE)
- s = name ? ":null" : "null";
- else if (fmt->json_format == UL_JSON_COMPACT)
- s = name ? ":null" : "null";
- else
+ if (fmt->json_format == UL_JSON_PRETTY)
s = name ? ": null" : "null";
+ else
+ s = name ? ":null" : "null";
break;
}
fputs(s, fmt->out);
return;
}
+ /* In COMPACT, when closing a direct child of root (indent==1),
+ * insert a newline so the closing bracket starts on its own line. */
if (fmt->json_format == UL_JSON_COMPACT && fmt->indent == 1)
fputc('\n', fmt->out);
"search type specified using -t"));
if (!ctl.eval && ctl.output & OUTPUT_JSON) {
- ul_jsonwrt_init(ctl.json_fmt, stdout, 0);
+ ul_jsonwrt_init(ctl.json_fmt, stdout, 0, UL_JSON_PRETTY);
ul_jsonwrt_root_open(ctl.json_fmt);
ul_jsonwrt_array_open(ctl.json_fmt, "blkid");
}