jq
Is a lightweight and flexible command line JSON processor. #我github It is an open source tool that can run on various operating systems, including Linux, OS X, Windows, etc. jq
Provides a wealth of operators and functions, making processing JSON data very convenient.
Here are some jq
basic uses:
.[]
: Traverse an array or object. For example,echo '[{"name":"John"},{"name":"Doe"}]' | jq '.[]'
two objects are output..key
: Get the value of a key of the object. For example,echo '{"name":"John"}' | jq '.name'
will be output"John"
.|
: Pipeline operator, which can pass the result of the previous expression to the next expression. For example, andecho '[{"name":"John"},{"name":"Doe"}]' | jq '.[] | .name'
would be output ."John"
"Doe"
jq
Very useful when processing JSON data returned by the GitHub API . For example, you can use jq -r '.[] | .stargazers_count'
to get the number of stars for each warehouse.
If it is not installed on your system jq
, you can download and install it from its official website: https://stedolan.github.io/jq/. In many Linux distributions you can also install using a package manager jq
, such as is available on Ubuntu sudo apt-get install jq
.