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

arrays unexpectedly wrapping return values #15

Closed
wxgeorge opened this issue Jul 23, 2019 · 2 comments
Closed

arrays unexpectedly wrapping return values #15

wxgeorge opened this issue Jul 23, 2019 · 2 comments

Comments

@wxgeorge
Copy link

wxgeorge commented Jul 23, 2019

This gem seems to deviate from the jq binary with regards to the return type of certain queries. Specifically, arrays are wrapping the return value in a number of situations.

Line 22 of spec/jq_spec.rb has

expect(JQ('"Zzz"').search('.')).to eq(['Zzz'])

But running the same query with the jq binary gives

echo '"Zzz"' | jq '.'
# "Zzz"

Why is the addition of the array the appropriate behaviour?

@wxgeorge
Copy link
Author

(jq is an awesome tool, and I'm very happy this gem exists - 🙏 thank you @winebarrel! - and I'd very like to use it in my projects, I just can't make sense of this behaviour ...)

@voke
Copy link

voke commented Sep 1, 2019

I guess it's because jq can produce multiple outputs and will print a newline after each output.

echo '["foo", "bar"]' | jq '.[] | ascii_upcase'

Result:

"FOO"
"BAR"

JQ('["foo", "bar"]').search('.[] | ascii_upcase')

Result:

["FOO", "BAR"]

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

No branches or pull requests

2 participants