学习笔记之jq

jq

  • https://stedolan.github.io/jq/
  • jq is a lightweight and flexible command-line JSON processor.
  • jq is like sed for JSON data - you can use it to slice and filter and map and transform structured data with the same ease that sedawkgrep and friends let you play with text.
  • jq is written in portable C, and it has zero runtime dependencies. You can download a single binary, scp it to a far away machine of the same type, and expect it to work.
  • jq can mangle the data format that you have into the one that you want with very little effort, and the program to do so is often shorter and simpler than you'd expect.
  • https://stedolan.github.io/jq/tutorial/
    • curl 'https://api.github.com/repos/stedolan/jq/commits?per_page=5' | jq '.'
    • curl 'https://api.github.com/repos/stedolan/jq/commits?per_page=5' | jq '.[0]'
    • jq '.[0] | {message: .commit.message, name: .commit.committer.name}'
    • curl 'http://...' | jq '.[] | "curl " + .url + "| jq .message > test.json"'
    • cat test.json | jq . > new.json
  • https://stedolan.github.io/jq/manual/

How to install jq on linux system ?

  • Download jq-linux64 from jq (stedolan.github.io)
  • Put it under one directory in PATH, e.g. ~/bin
  • $ chmod +x jq-linux64
  • $ mv jq-linux64 jq
  • $ jq
  • $ echo '{"foo": 0}' | jq .
 

 

posted on 2020-10-20 10:47  浩然119  阅读(115)  评论(0编辑  收藏  举报