1

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

1 Answer 1

1

You can use like:

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

program being the program producing that output.

Sign up to request clarification or add additional context in comments.

4 Comments

This command was not working in jq-1.3 version, but its work on jq-1.6 version
jq: Unknown option -Rn Use jq --help for help with command-line options, or see the jq documentation at stedolan.github.com/jq
@satheeshkumar right, it may not work on obsolete versions
If possible can you share jq command which can work on 1.3 version

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.