Let me just explain what task I was trying to accomplish:
I have a file A.json of a dict, and I want to generate a file B.txt,
with one key per line, and no quotation marks around the keys. I get close with
cat A.json | jq 'keys[]'
But I had to use cut to drop the leading and trailing quotes from the keys, and that only worked because they were youtube_ids and all the same length.
It would be great if there was a print command in jq that dropped the extra quotes that I don't need.
Is the --raw-output / -r option good enough?
jq --raw-output 'keys[]' A.json
Yes, it is. I read the manual, and the tutorial, and didn't find that, so
thanks a ton.
On Fri, Feb 7, 2014 at 3:25 PM, Nico Williams [email protected]:
Is the
--raw-output/-roption good enough?jq --raw-output 'keys[]' A.json
Reply to this email directly or view it on GitHubhttps://github.com/stedolan/jq/issues/286#issuecomment-34518439
.
Curious why --raw-output isn't the default. If I curl to get the latest tag for a GitHub repo, for example, I don't want it surrounded with quotes. I'm wondering why anyone would by default.
$ curl https://api.github.com/repos/docker/machine/releases/latest | jq -r ".tag_name"
v0.7.0
Such a common kind of thing that I'd rather have a -q option if I really wanted quotes.
@subfuzion - By default, jq expects the input to be JSON, and by default produces JSON as output. That corresponds nicely with the symmetry between the -R and -r options. And the "j" in "jq" is for JSON, after all.
Most helpful comment
Is the
--raw-output/-roption good enough?