如何将输出转换为 JSON 格式?

How to convert output into JSON format?

我正在尝试将以下输出转换为有效的 json 输出。 无法使用 shell 脚本解决此问题。

输出

svc pts/0        localhost. Tue Apr 28 21:40   still logged in   
svc pts/0        localhost. Tue Apr 28 21:40 - 21:40  (00:00)    
svc pts/0        localhost. Tue Apr 28 21:40 - 21:40  (00:00)
...etc

有效json输出

{
    "Result": [{
        "models": ["svc pts 0 localhost.Tue Apr 28 21: 40 still logged in",
            "svc pts/0        localhost. Tue Apr 28 21:40 - 21:40  (00:00)"
        ]
    }]
}

可以转换吗?有人可以提供 solution.s

您可以像这样使用

program | jq -Rn '{Result:[{models:[inputs]}]}'

program 是产生该输出的程序。