-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
only first find #1188
Comments
You could use the -n option together with 'inputs' and 'first', along the lines of:
|
thanks for answer. |
You basically have a collection of objects, all peers, not related to each other. If you load them with jq -s, it will wrap them in an array, and you could then select the 123th object like so: cat sample.json | jq -s '.[122]' (the first one being [0], of course...) Aside from indexing them within a containing array or object, I don't know of a way to isolate just the one you want. |
@s3c1t - Again with the -n option: nth(122; items) That avoids the need to use -s |
very thanks for answers. |
@s3c1t, did you try:
That works for me, and is tremendously faster than the |
thanks for answers. output: |
in the other word I.e. jq '. | if ... then "print something; exit jq" else ... end' |
+1 on the "find first"/"find one" functionality |
@arnm There is. In OP's case the thing to do is |
@s3c1t The |
i have a big json file
for example
{"id":"abc","data":"test1"}
{"id":"wer","data":"test2"}
{"id":"trg","data":"test3"}
....
i used this command for extract specific value filed As follows:
cat sample.json |jq 'if .id == "wer" then .data else empty end '
but jq search continues to end big json file and not exit.
Now my question is: how to exit jq after first matching
The text was updated successfully, but these errors were encountered: