最後更新: 2017-12-20
介紹
jq is sed for JSON
Command-line JSON processor
jq is written in portable C, and it has zero runtime dependencies.
HomePage: https://stedolan.github.io/jq/
Install
apt-get install jq
# The simplest filter is "." which echoes its input, but pretty-printed:
echo '{"hello":{ "greetings":"to you"}}' | jq .
jq '.' file.json
# ".field" which pulls field out of each record:
# .field1.field2 for nested hashes
echo '{"hello":{ "greetings":"to you"}}' | jq .hello
echo '{"hello":{ "greetings":"to you"}}' | jq .hello.greetings
# array
echo '["a","b","c","d","e"]' | jq '.[2:4]'
# go “into” the array
jq ".[]"
# filter by text
jq ".[] | .text"