242

I have a json and at the moment using select to get only the data which match one condition, I need to filter based on more conditions.

For e.g:

.[] | select((.processedBarsVolume <= 5) && .processedBars > 0)

How I can do this ?

jq170727
  • 13,159
  • 3
  • 46
  • 56
Andrei Colta
  • 2,542
  • 2
  • 10
  • 4

2 Answers2

471

jq supports the normal Boolean operators and/or/not, so it would look like:

.[] | select((.processedBarsVolume <= 5) and .processedBars > 0)
Hans Z.
  • 50,496
  • 12
  • 102
  • 115
3

I had to wrap the piping to startswith with parentheses in order to make this work.

jq -n 'env | with_entries(select ((.key|startswith("CI_")) or .key == "DOCKER_CONTAINER_VERSION_TAG"))'
siyb
  • 2,837
  • 2
  • 21
  • 18