-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Description
Description
I would like to see a feature that folds compact json content at N characters while still keeping it as valid json. Such a feature would allow users to easily produce valid compact json that could be embedded into documents that restrict line length.
Attempted alternatives
fold
fold
produces invalid json:
# lsblk -J | jq -c . | fold -s
{"blockdevices":[{"name":"nbd0","maj:min":"43:0","rm":false,"size":"0B","ro":fal
se,"type":"disk","mountpoints":[null]},{"name":"nbd1","maj:min":"43:32","rm":fal
se,"size":"0B","ro":false,"type":"disk","mountpoints":[null]},{"name":"nbd2","ma
j:min":"43:64","rm":false,"size":"0B","ro":false,"type":"disk","mountpoints":[nu
ll]},{"name":"nbd3","maj:min":"43:96","rm":false,"size":"0B","ro":false,"type":"
disk","mountpoints":[null]},{"name":"zram0","maj:min":"253:0","rm":false,"size":
"15.7G","ro":false,"type":"disk","mountpoints":["[SWAP]"]},{"name":"vda","maj:mi
n":"254:0","rm":false,"size":"362.4M","ro":true,"type":"disk","mountpoints":[nul
l]},{"name":"vdb","maj:min":"254:16","rm":false,"size":"8T","ro":false,"type":"d
isk","mountpoints":[null],"children":[{"name":"vdb1","maj:min":"254:17","rm":fal
se,"size":"460.4G","ro":false,"type":"part","mountpoints":["/etc/hosts","/etc/ho
stname","/etc/resolv.conf"]}]},{"name":"vdc","maj:min":"254:32","rm":false,"size
":"1G","ro":false,"type":"disk","mountpoints":["[SWAP]"]}]}
Regex
Using a regex can sometimes produce valid json, but would be unreliable, and suboptimal:
# lsblk -J | jq -c . | sed -E 's/(.{1,80}),/\1,\n/g'
{"blockdevices":[{"name":"nbd0","maj:min":"43:0","rm":false,"size":"0B",
"ro":false,"type":"disk","mountpoints":[null]},{"name":"nbd1","maj:min":"43:32",
"rm":false,"size":"0B","ro":false,"type":"disk","mountpoints":[null]},
{"name":"nbd2","maj:min":"43:64","rm":false,"size":"0B","ro":false,"type":"disk",
"mountpoints":[null]},{"name":"nbd3","maj:min":"43:96","rm":false,"size":"0B",
"ro":false,"type":"disk","mountpoints":[null]},{"name":"zram0","maj:min":"253:0",
"rm":false,"size":"15.7G","ro":false,"type":"disk","mountpoints":["[SWAP]"]},
{"name":"vda","maj:min":"254:0","rm":false,"size":"362.4M","ro":true,
"type":"disk","mountpoints":[null]},{"name":"vdb","maj:min":"254:16","rm":false,
"size":"8T","ro":false,"type":"disk","mountpoints":[null],
"children":[{"name":"vdb1","maj:min":"254:17","rm":false,"size":"460.4G",
"ro":false,"type":"part","mountpoints":["/etc/hosts","/etc/hostname",
"/etc/resolv.conf"]}]},{"name":"vdc","maj:min":"254:32","rm":false,"size":"1G",
"ro":false,"type":"disk",
"mountpoints":["[SWAP]"]}]}
Metadata
Metadata
Assignees
Labels
No labels