Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip quotes from strings #286

Closed
tbelaire opened this issue Feb 7, 2014 · 4 comments
Closed

Strip quotes from strings #286

tbelaire opened this issue Feb 7, 2014 · 4 comments
Labels

Comments

@tbelaire
Copy link

tbelaire commented Feb 7, 2014

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.

@nicowilliams
Copy link
Contributor

Is the --raw-output / -r option good enough?

jq --raw-output 'keys[]' A.json

@tbelaire
Copy link
Author

tbelaire commented Feb 7, 2014

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 notifications@github.comwrote:

Is the --raw-output / -r option good enough?

jq --raw-output 'keys[]' A.json

Reply to this email directly or view it on GitHubhttps://github.com//issues/286#issuecomment-34518439
.

@subfuzion
Copy link

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.

@pkoppstein
Copy link
Contributor

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants