5 ms·
If 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
by 10000truths 3y ago
If 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.