Get outputs from jq on a single line

JsonJq

Json Problem Overview


I got below output using: https://stackoverflow.com/a/40330344

 (.issues[] | {key, status: .fields.status.name, assignee: .fields.assignee.emailAddress})

Output:

 {  
   "key": "SEA-739",
   "status": "Open",
   "assignee": null
 }
 {
   "key": "SEA-738",
   "status": "Resolved",
   "assignee": "[email protected]"
 }

But I need to parse each and every line but it's tough to identify which assignee is for which key as far as key group is concerned. Is this possible to make one bunch in one row using jq?

Expected output:

{ "key": "SEA-739", "status": "Open", "assignee": null }
{ "key": "SEA-738", "status": "Resolved", "assignee": "[email protected]"}

OR

{ "SEA-739", "Open", null }
{ "SEA-738", "Resolved", user2@mycompany.com }

Json Solutions


Solution 1 - Json

-c is what you likely need

Using the output you posted above, you can process it further:

jq -c . input

To Give;

{"key":"SEA-739","status":"Open","assignee":null}
{"key":"SEA-738","status":"Resolved","assignee":"[email protected]"}

Or you can just change your original command

FROM

jq -r '(.issues[] | {key, status: .fields.status.name, assignee: .fields.assignee.emailAddress})'

TO

jq -c '(.issues[] | {key, status: .fields.status.name, assignee: .fields.assignee.emailAddress})'

Solution 2 - Json

Not precisely an answer to the long version of the question, but for people who Googled this looking for other single line output formats from jq:

$ jq -r '[.key, .status, .assignee]|@tsv' <<<'
 {
   "key": "SEA-739",
   "status": "Open",
   "assignee": null
 }
 {
   "key": "SEA-738",
   "status": "Resolved",
   "assignee": "[email protected]"
 }'
SEA-739 Open
SEA-738 Resolved        user2@mycompany.com

@sh rather than @tsv returns:

'SEA-739' 'Open' null
'SEA-738' 'Resolved' '[email protected]'

Additionally, there are other output formats to do things such as escape the output, like @html, or encode it, as with @base64. The list is available in the Format strings and escaping section of either the jq(1) man page or online at stedolan.github.io/jq/manual.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJitesh SojitraView Question on Stackoverflow
Solution 1 - Jsonhmedia1View Answer on Stackoverflow
Solution 2 - JsonbschlueterView Answer on Stackoverflow