JSON解析利器jq安装

2018-09-29  本文已影响0人  LI木水

安装jq

Ubuntu可以直接用apt安装

sudo apt-get install jq

mac下安装

brew install jq

centos好像没有直接安装的命令
依次运行以下命令

wget https://github.com/stedolan/jq/releases/download/jq-1.5/jq-1.5.tar.gz
tar -xzvf jq-1.5.tar.gz 
cd jq-1.5/
./configure && make && sudo make install

使用jq

查看帮助

[root@Ieat1 jq-1.5]# jq
jq - commandline JSON processor [version 1.5]
Usage: jq [options] <jq filter> [file...]

    jq is a tool for processing JSON inputs, applying the
    given filter to its JSON text inputs and producing the
    filter's results as JSON on standard output.
    The simplest filter is ., which is the identity filter,
    copying jq's input to its output unmodified (except for
    formatting).
    For more advanced filters see the jq(1) manpage ("man jq")
    and/or https://stedolan.github.io/jq

    Some of the options include:
     -c     compact instead of pretty-printed output;
     -n     use `null` as the single input value;
     -e     set the exit status code based on the output;
     -s     read (slurp) all inputs into an array; apply filter to it;
     -r     output raw strings, not JSON texts;
     -R     read raw strings, not JSON texts;
     -C     colorize JSON;
     -M     monochrome (don't colorize JSON);
     -S     sort keys of objects on output;
     --tab  use tabs for indentation;
     --arg a v  set variable $a to value <v>;
     --argjson a v  set variable $a to JSON value <v>;
     --slurpfile a f    set variable $a to an array of JSON texts read from <f>;
    See the manpage for more options.

安装参考https://stedolan.github.io/jq/download/
使用参考 https://www.ibm.com/developerworks/cn/linux/1612_chengg_jq/index.html
json->csv https://lombardo-chcg.github.io/tools/2017/12/16/json-to-csv-using-jq.html

上一篇 下一篇

猜你喜欢

热点阅读