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

jq doesn't parse colorized JSON #1787

Closed
nexxai opened this issue Jan 9, 2019 · 5 comments
Closed

jq doesn't parse colorized JSON #1787

nexxai opened this issue Jan 9, 2019 · 5 comments

Comments

@nexxai
Copy link

nexxai commented Jan 9, 2019

Describe the bug
When piping output from azure-cli (az) to jq it fails with a parse error. If I manually select the text and pipe it into jq by way of the 'echo' command, it works fine.

To Reproduce
az account list --query '[].id' | jq '.[]'

Expected behavior
// Doesn't work:

sh$ az account list --query '[].id' | jq '.[]'
"a86bc126-XXXX-XXXX-XXXX-7e546be7a509"                   // Expected
parse error: Invalid numeric literal at line 2, column 4 // Actual
sh$

// Works:

sh$ az account list --query '[].id'
[
  "a86bc126-XXXX-XXXX-XXXX-7e546be7a509"
]
sh$ echo '["a86bc126-XXXX-XXXX-XXXX-7e546be7a509"]' | jq '.[]'
"a86bc126-XXXX-XXXX-XXXX-7e546be7a509"
sh$

Environment (please complete the following information):

  • OS and Version: macOS Mojave 10.14.2 (18C54)
  • jq version 1.6

Additional context
n/a

@wtlangford
Copy link
Contributor

wtlangford commented Jan 9, 2019 via email

@nexxai
Copy link
Author

nexxai commented Jan 9, 2019

I think you're on to something. I use a colored terminal (oh_my_zsh) and when I piped the output of az account to a file, it also included the ANSI(?) color codes like this:

[
  �[33m"a86bc126-XXXX-XXXX-XXXX-7e546be7a509"�[39;49;00m
]

I'm not sure how big an ask this is, but would it be possible to add filtering in jq to look for (and discard) those codes?

@wtlangford
Copy link
Contributor

I'd rather not teach our parser to ignore those for a variety of reasons.

That said, it looks like az has an output mode that doesn't include the color codes, though. Try az -o json account list --query '[].id' | jq '.[]' and see if that works?

@nicowilliams
Copy link
Contributor

Maybe the az command should not colorize output when it goes to a pipe... Maybe az should learn from jq...

@nicowilliams nicowilliams changed the title parse error: Invalid numeric literal at line 2, column 4 jq doesn't parse colorized JSON Jan 9, 2019
@nicowilliams
Copy link
Contributor

Good debugging. It actually might not be crazy to teach jq about color... But I too would rather not.

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

No branches or pull requests

3 participants