After a bit of fiddling with the jq
tool:
jq --arg l "My Label" --arg p /path/to/folder \
'{ id: . | keys[], label: $l, path: $p, devices: .[].offeredBy | keys | map({ deviceID: . }) }'\
<<EOF
{
"kmmgl-nygfm": {
"offeredBy": {
"Z2M6GO2-455NXSO-CQLJVBB-IIG5MPA-ERT636W-LUK3GUC-MUSIBP6-6UIVQQF": {
"time": "2021-10-20T18:18:40Z",
"label": "syncthing-restAPI",
"receiveEncrypted": false,
"remoteEncrypted": false
}
}
}
}
EOF
{
"id": "kmmgl-nygfm",
"label": "My Label",
"path": "/path/to/folder",
"devices": [
{
"deviceID": "Z2M6GO2-455NXSO-CQLJVBB-IIG5MPA-ERT636W-LUK3GUC-MUSIBP6-6UIVQQF"
}
]
}
(Note the <<EOF
so-called heredoc syntax is just for this example usage. Redirect from a file or build a pipe as you see fit in your use case.)
Obviously doesn’t handle all the details, but it’s a start for most stuff that can be processed automatically. remoteEncrypted
cries for a password to be supplied if true. The label can be different when offered from several devices, so it’s ambiguous which one to pick.