satheesh kumar
satheesh kumar

Reputation: 91

How to convert output into JSON format?

I am trying to convert below output into a valid json output. Cant able to solve this using shell scripts.

output

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

valid json output

{
    "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)"
        ]
    }]
}

is it possible to convert? can someone provide solution.s

Upvotes: 1

Views: 330

Answers (1)

oguz ismail
oguz ismail

Reputation: 50750

You can use like:

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

program being the program producing that output.

Upvotes: 1

Related Questions