Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get outputs from jq on a single line

Tags:

json

jq

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", [email protected] } 
like image 364
Jitesh Sojitra Avatar asked Nov 03 '16 08:11

Jitesh Sojitra


People also ask

Does jq use JSONPath?

JSONPath distinguishes between the "root object or element" ($) and "the current object or element" (.). jq simply uses . to refer to the current JSON entity and so it is context-dependent: it can refer to items in the input stream of the jq process as a whole, or to the output of a filter.

What is jq in command line?

jq is a lightweight and flexible command-line JSON processor. It is like sed for JSON data – you can use it to slice and filter and map and transform structured data with the same ease that sed, awk, grep and friends let you play with text. jq is a fantastic command-line JSON processor.

Can jq write JSON?

jq is an amazing little command line utility for working with JSON data.


1 Answers

-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})' 
like image 69
hmedia1 Avatar answered Sep 29 '22 15:09

hmedia1