I've written a script that converts the output of
nmcli --mode multiline dev wifi into JSON,
but I'm finding it's inconsistent (breaks when results have a space),
long, and hard to read.
I wonder if it is possible to pipe the results directly into jq.
The nmcli output (input to my script) looks like this:
*:
SSID: VIDEOTRON2255
MODE: Infra
CHAN: 11
RATE: 54 Mbit/s
SIGNAL: 69
BARS: ▂▄▆_
SECURITY: WPA1 WPA2
*: *
SSID: VIDEOTRON2947
MODE: Infra
CHAN: 6
RATE: 54 Mbit/s
SIGNAL: 49
BARS: ▂▄__
SECURITY: WPA1 WPA2
I'm looking to generate something like this:
[{
"network": "VIDEOTRON2255",
"mode": "Infra",
"chan": "11",
"rate": "54 Mbit/s",
"signal": "69",
"bars": "▂▄▆_",
"security": "WPA1 WPA2"
},
{
"network": "VIDEOTRON2947",
"mode": "Infra",
"chan": "6",
"rate": "54 Mbit/s",
"signal": "49",
"bars": "▂▄__",
"security": "WPA1 WPA2"
}]
I asked a related question earlier. This is the first script I wrote based on Gilles's answer. It worked for some of the values but not security or rate, which have spaces.