bash

    1. _json=$(
    2. echo '{}' |
    3. jq --arg v "$(date +"%Y-%m-%d %T")" '.time[0]=$v' |
    4. jq --arg v "$(date '+%s')" '.time[1]=$v' |
    5. jq --arg v "200" '.code=$v' |
    6. jq --argjson v "[]" '.data=$v' -c
    7. )
    8. echo "$_json" | jq

    返回

    1. {
    2. "time": [
    3. "2021-12-23 20:53:21",
    4. "1640264001"
    5. ],
    6. "code": "200",
    7. "data": []
    8. }