Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 657

jq - Append element after picking

$
0
0

System Information

jq: 1.7

Pick

  • Following command works correctly as expected:
jq 'pick(.id,.title,.webpage_url,.channel,.duration_string,.upload_date)' *.info.json
{"id": "uO8Sn0Xch1s","title": "A transformative new way of classifying foods 🍔🍕🍟 BBC","webpage_url": "https://www.youtube.com/watch?v=uO8Sn0Xch1s","channel": "BBC","duration_string": "4:19","upload_date": "20210701"}

Pick and Append

$ Date=$(date +%Y-%m-%d)$ jq 'pick(.id,.title,.webpage_url,.channel,.duration_string,.upload_date)' *.info.json \  | jq --arg Date="$Date" '. += {"date": $Date}'
{"id": "uO8Sn0Xch1s","title": "A transformative new way of classifying foods 🍔🍕🍟 BBC","webpage_url": "https://www.youtube.com/watch?v=uO8Sn0Xch1s","channel": "BBC","duration_string": "4:19","upload_date": "20210701"}

Issue

  1. Pick and Append produces same output as Pick and is not appending date. Why and how can I correct this?
  2. also tried + instead of +=, both didn't work (but should work as per Reference 2)

Expected Output

{"id": "uO8Sn0Xch1s","title": "A transformative new way of classifying foods 🍔🍕🍟 BBC","webpage_url": "https://www.youtube.com/watch?v=uO8Sn0Xch1s","channel": "BBC","duration_string": "4:19","upload_date": "20210701","date": "2024-05-10"}

Reference


Viewing all articles
Browse latest Browse all 657

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>