Riaan's SysAdmin Blog

My tips, howtos, gotchas, snippets and stuff. Use at your own risk!

Uncategorized

Gnuplot json data

Quick and dirty way to get a graph of your json series.

My data is OTA channel test data and your challenge is to massage it into a CSV. Mine based on below jq turned out like this.

$ cat generated.csv 
2025-11-29T22:50:46.9215829Z,100
2025-11-29T22:51:45.1381811Z,100
2025-11-30T17:55:34.2705405Z,100
2025-11-30T21:48:26.7645935Z,100

My script

$ cat generate_metrics.sh
#!/usr/bin/env bash

# NOTE: I got test.json by dos2unix the actual json and adding opening and closing list [] plus comma seperating items
#       Need to improve this

#CHANNEL="KRIV-DT"
CHANNEL=$1

#LOG_FILE="./metrics.log"
CSV_FILE="./generated.csv"
GNUPLOT_SCRIPT_FILE="./gnuplot_script.gp"
GNUPLOT_GRAPHIC_FILE="./metrics/${CHANNEL}_metrics.png"

function generateCsvFile {
  #cat $LOG_FILE | jq -r 'to_entries|map(.value)|@csv' | tr -d '"' > $CSV_FILE
  cat test.json | jq --arg channel ${CHANNEL} -r '.[] | {"time": .timestamp , "tuners": .tuners[] | select(.name==$channel)} | "\(.time),\(.tuners.seq)"' > $CSV_FILE
}

function generateGraphic {
  gnuplot -e "csv_file_path='$CSV_FILE'" -e "graphic_file_name='$GNUPLOT_GRAPHIC_FILE'" $GNUPLOT_SCRIPT_FILE
}

generateCsvFile
generateGraphic
exit

admin

Bio Info for Riaan