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 work #22

Closed
m-titov opened this issue May 19, 2022 · 2 comments
Closed

jq doesn't work #22

m-titov opened this issue May 19, 2022 · 2 comments

Comments

@m-titov
Copy link

m-titov commented May 19, 2022

 curl https://wttr.in/Detroit\?format\=j1 | jq '.weather|.[].date'                                  [2022-05-19 23:58:52]
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 48898  100 48898    0     0   112k      0 --:--:-- --:--:-- --:--:--  115k
"2022-05-19"
"2022-05-20"
"2022-05-21"

works as expected but Virtual Json Viewer plugin throws Unexpected string in JSON at position 13 error for the same expression:
.weather|.[].date

See also https://jqplay.org/s/DHmRZozMOj9
Could you please fix it and make my life easier?

@paolosimone
Copy link
Owner

Hi @m-titov, first of all thanks for using my plugin!

TLDR;

use .weather | map(.date) instead


Complete explanation

Virtual Json Viewer is a plugin to render json in the browser, so jq commands must output a valid json.

Unfortunately the following is not a valid json array

"2022-05-19"
"2022-05-20"
"2022-05-21"

While this is

curl -s https://wttr.in/Detroit\?format\=j1 | jq '.weather | map(.date)'
[
  "2022-05-20",
  "2022-05-21",
  "2022-05-22"
]

@paolosimone
Copy link
Owner

Since this behaviour is a bit tricky I added a more in-depth section to the readme

https://github.com/paolosimone/virtual-json-viewer#notes-on-jq

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