티스토리 뷰

공부

[sh] python jq

승가비 2023. 3. 12. 23:22
728x90
pip3 install jq

parse() {
  key=$1

  python3 -c "
import sys
import jq
import json

input = json.load(sys.stdin)
output = jq.compile('$key').input(input).all()

if(isinstance(output, list)):
    output = ' '.join(output)

print(output)
"
}

name=$(aws emr describe-cluster --cluster-id $id | parse ".Cluster.Name")

echo $name

https://stackoverflow.com/questions/1955505/parsing-json-with-unix-tools?page=2&tab=scoredesc#tab-top 

 

Parsing JSON with Unix tools

I'm trying to parse JSON returned from a curl request, like so: curl 'http://twitter.com/users/username.json' | sed -e 's/[{}]/''/g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<...

stackoverflow.com

https://pypi.org/project/jq/

 

jq

jq is a lightweight and flexible JSON processor.

pypi.org

 

728x90
댓글