JQ

AWS cli 세팅하기 참고.

https://stedolan.github.io/jq/tutorial/ 기본 예제부터 이해함

 

특정 값만 뽑을 때는 select 이용.

$ sg_address="aws_security_group.$sg" $ cat show-json | jq .values.root_module[] \ | jq -r --arg sg_address "$sg_address" '.[] | select(.address==$sg_address)' \ | jq '. | {address: .address, id: .values.id, name: .values.name}'

https://stedolan.github.io/jq/manual/

 

jq 에서 variable 넘기는 것.

https://stackoverflow.com/questions/40027395/passing-bash-variable-to-jq

projectID=$(jq -r --arg EMAILID "$EMAILID" ' .resource[] | select(.username==$EMAILID) | .id' file.json)

 

json to csv
https://e.printstacktrace.blog/how-to-convert-json-to-csv-from-the-command-line/

$ cat jobs.json | jq '[.[0] | {id,title,url,company,location}]' [ { "id": "9ef799fa-5253-47bc-a101-82557c675e4d", "title": "QA Automation Engineer (m/f/d)", "url": "https://jobs.github.com/positions/9ef799fa-5253-47bc-a101-82557c675e4d", "company": "Scanbot / doo GmbH", "location": "Bonn" } ] $ jq -r 'map({id,title,url,company,location}) | (first | keys_unsorted) as $keys | map([to_entries[] | .value]) as $rows | $keys,$rows[] | @csv' jobs.json "9ef799fa-5253-47bc-a101-82557c675e4d","QA Automation Engineer (m/f/d)","https://jobs.github.com/positions/9ef799fa-5253-47bc-a101-82557c675e4d","Scanbot / doo GmbH","Bonn" "dec1d370-c5fa-4103-b3ca-ad5e24ce4fb6","Fullstack Entwickler (React & Kolin/Java) - azeti IoT platform","https://jobs.github.com/positions/dec1d370-c5fa-4103-b3ca-ad5e24ce4fb6","azeti GmbH","Berlin" "85c06c71-e088-413c-9db2-a6709ecba809","Webentwickler Typescript / Angular (m/w/d)","https://jobs.github.com/positions/85c06c71-e088-413c-9db2-a6709ecba809","CompuGroup Medical SE & Co. KGaA","Nürnberg" "712212cc-6214-4236-99d9-605cf35a82d3","Software Engineer","https://jobs.github.com/positions/712212cc-6214-4236-99d9-605cf35a82d3","Neonomics AS","Oslo, Norway" "bb7b1579-105c-44f8-9d8a-d0c7d7160806","Full Stack Engineer","https://jobs.github.com/positions/bb7b1579-105c-44f8-9d8a-d0c7d7160806","SocialVenu","Remote (North America Only)" "377e8e58-7bd1-45ca-8ccf-4d633381d4c8","Senior Enterprise Software Engineer (Kotlin)","https://jobs.github.com/positions/377e8e58-7bd1-45ca-8ccf-4d633381d4c8","Ikayzo","United States" "7d20a54c-244b-4d92-9c6b-66c85cdbf876","Senior Backend Engineer (Kotlin/Spring boot)","https://jobs.github.com/positions/7d20a54c-244b-4d92-9c6b-66c85cdbf876","Superside","Remote/Europe" "1f0bc6cd-6347-48a1-8754-98b09c264cf2","Frontend Engineer (React/NextJS)","https://jobs.github.com/positions/1f0bc6cd-6347-48a1-8754-98b09c264cf2","Superside","Remote"