Comments (2)
./jq 'if .foo == "bar" then empty end'
would do what you want. empty
is a builtin that produces zero results. You can in theory implement it yourself with something like [][]
(each element of an empty array).
You should probably use the (sadly undocumented) builtin function select
instead:
./jq 'select(.foo == "bar")'
I intentionally didn't implement if-without-else, since I'm not sure whether the best default for "else" behaviour is produce-no-output or dont-change-the-input (that is, whether the implicit else block should be .
or empty
). This sounds like a vote for empty
.
from jq.
Ah. Brilliant. I don't think there's any need for if-without-else in the presence of select and empty. Closing this ticket because there's no issue with jq, just a gap in the docs. Cheers.
from jq.
Related Issues (20)
- CVE-2023-49355 status ? HOT 2
- Tests don't work in non-decnumber builds
- Feature Request - Full Path Json output HOT 5
- Broken non-Latin output HOT 14
- Version 1.7.1 not working well on XcodeCloud HOT 4
- 1 test fails on WSL Debian HOT 14
- Version number pattern
- Base64d filter is not working as expected. HOT 2
- Allow user to control colors of int/bool/number HOT 2
- Incorrect results when subtracting two long numbers HOT 2
- make test failed under WSL, version jq 1.7.1-8-gf51e841 HOT 3
- Adding `sort_keys` filter as a flexible alternative to `--sort-keys` HOT 10
- Typo in the manual HOT 1
- try-catch + ascii_downcase fails in "catch" condition HOT 5
- Error suppression operator breaks function behaviour HOT 2
- Unrecognized HTML entity: `©` while running xq command HOT 1
- Setting non-existent elements of array slices uncovers hidden elements
- nan123 HOT 6
- Feature: Allow keys/array strings to be different color than object keys
- Modulo operator drops fractional part HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jq.