How to format a JSON string as a table using jq?

后端 未结 4 1493
闹比i
闹比i 2020-12-04 13:02

Just started out with Bash scripting and stumbled upon jq to work with JSON.

I need to transform a JSON string like below to a table for output in the terminal.

4条回答
  •  [愿得一人]
    2020-12-04 13:36

    If the values don't contain spaces, this might be helpful:

    read -r -a data <<<'name1 value1 name2 value2'
    
    echo "name value"
    echo "=========="
    
    for ((i=0; i<${#data[@]}; i+=2)); do
      echo ${data[$i]} ${data[$((i+1))]}
    done
    

    Output

    name value
    ==========
    name1 value1
    name2 value2
    

提交回复
热议问题