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

add command inside if in jq #2053

Closed
gianfabiopezzolla opened this issue Jan 29, 2020 · 4 comments
Closed

add command inside if in jq #2053

gianfabiopezzolla opened this issue Jan 29, 2020 · 4 comments
Labels

Comments

@gianfabiopezzolla
Copy link

Hi there,

I have this following script:

sqtoken="myToken"
project_name=proj_name
sonar_search=`curl -u $sqtoken: http://my.sonar.it/api/projects/search?projects=$project_name`

echo $sonar_search | jq 'if (.components == []) then empty else .components end'

I need to add a curl -X POST http:// inside the first if in jq,
How can I do that?

Thanks a lot

@leonid-s-usov
Copy link
Contributor

@nicowilliams this is your moment :)
@sagolab please see pr #1843 , it will add the possibility of running external process from within JQ

@gianfabiopezzolla
Copy link
Author

@leonid-s-usov ok thanks a lot. So is not possible yet..

@nicowilliams
Copy link
Contributor

Yeah, #1843 is the thing for this. Soon.

@itchyny itchyny added the support label Jun 3, 2023
@emanuele6
Copy link
Member

I don't understand the question.

Anyway you can easily run commands piping to sh.

Here is an example: (I don't think it's correct since .components would be an array, but I don't know how else to interpret the question.)

curl -fGu "$sqtoken:" --data-raw "projects=$project_name" \
    http://my.sonar.it/api/projects/search |
jq -r '
    .components |
    select(. != []) |
    @sh "curl -gfX POST http://\(.components)"' |
sh

Closing...

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