3 ms·
I guess I have a terrible imagination. Can someone provide a concrete example of when this should be used?
by callalex 3y ago
I guess I have a terrible imagination. Can someone provide a concrete example of when this should be used?
- bartvk 3y agoI could see this being useful when you coded a utility, which runs off a huge existing JSON as its configuration. You want to go straight for one or two values, not this huge data structure.
- beardyw 3y agoFor me, if I am scripting something, do curl, extract value from returned JSON, continue ...
- 10000truths 3y agoIf I receive a JSON list of JSON objects from an API call, but only a few of the objects' fields are relevant to me, then I can do something like: curl https://example.com/api/orders | jq '.data[] | pick(.date, .amount)'
- pcthrowaway 3y agoWhen would this be better than curl https://example.com/api/orders | jq '.data[] | {date, amount}' or curl https://example.com/api/orders | jq '[.data[] | {date, amount}]' if you want it collected back into an array?
- wwader 3y agoIn that case it would be very similar but pick is more general then the shorthand object literal syntax, it can be used with nested index lika .a.b.c or any expression like pick(if .a then .b else .c end) but both has it uses i think.