Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concat numbers from JSON without doublequotes using jq [duplicate]

Tags:

json

jq

I have files with 1 json document per row and the fields start_id and end_id in each document. I'd like to use jq to extract these and print them on the same row.

So far I have:

cat part* | jq '"\(.start_id) \(.end_id)"' | sed s/\"//g | head

This works, but I need the sed to remove the double quotes.

In order to improve my jq-foo, is there a way to do this without using sed?

e.g. given

{"start_id":1,"end_id":50}
{"start_id":50,"end_id":99}
{"start_id":99,"end_id":12}

get

1 50
50 99
99 12

instead of

"1 50"
"50 99"
"99 12"
like image 831
Synesso Avatar asked Nov 26 '15 22:11

Synesso


1 Answers

By default, jq formats its output to be a valid JSON value. This means that character strings are wrapped in quotes.

Fortunately, the --raw-output or -r parameter overrides that behaviour so your string output can be free of those nasty quotation marks.

like image 56
xjedam Avatar answered Oct 25 '22 17:10

xjedam