我有以下 json 作为 jq 处理的输入
[
{
"Category": "Disk Partition Details",
"Filesystem": "udev",
"Size": "3.9G",
"Used": 0,
"Avail": "3.9G",
"Use%": "0%",
"Mounted": "/dev"
},
{
"Category": "Disk Partition Details",
"Filesystem": "tmpfs",
"Size": "799M",
"Used": "34M",
"Avail": "766M",
"Use%": "5%",
"Mounted": "/run"
}
]
按照@peak here./csvtojson.sh bb.csv | jq 'map( {(.Category): del(.Category)})'
的建议使用 ,我已经达到了下面的json
[
{
"Disk Partition Details": {
"Filesystem": "udev",
"Size": "3.9G",
"Used": 0,
"Avail": "3.9G",
"Use%": "0%",
"Mounted": "/dev"
}
},
{
"Disk Partition Details": {
"Filesystem": "tmpfs",
"Size": "799M",
"Used": "34M",
"Avail": "766M",
"Use%": "5%",
"Mounted": "/run"
}
}
]
我想要的只是将类别放在顶部一次,然后像我在上一步中所做的那样将这个 json 分解到另一个级别。
[
{
"Disk Partition Details": {
"udev" :{
"Size": "3.9G",
"Used": 0,
"Avail": "3.9G",
"Use%": "0%",
"Mounted": "/dev"
},
"tmpfs" : {
"Size": "799M",
"Used": "34M",
"Avail": "766M",
"Use%": "5%",
"Mounted": "/run"
}
}
}
]