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

pass int into array index #605

Closed
rclod opened this issue Oct 27, 2014 · 2 comments
Closed

pass int into array index #605

rclod opened this issue Oct 27, 2014 · 2 comments
Labels

Comments

@rclod
Copy link

rclod commented Oct 27, 2014

I would like to be able to pass an variable of type int into an array index.

jq --arg INDEX 0 '.device_icons[$INDEX].width'

Ideally I would replace 0 with ${INDEX} in my code so that I can use this inside a loop, but even the snippet above gives me an error:

"jq: error: Cannot index array with string"

Is there a way to explicitly cast a "string" as an int?

@nicowilliams
Copy link
Contributor

Use '.device_icons[$INDEX | tonumber].width'.

@rclod
Copy link
Author

rclod commented Oct 27, 2014

Great, thanks!

@rclod rclod closed this as completed Oct 27, 2014
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

3 participants