Check if a file is a valid JSON in a BASH script

So, you have downloaded a file that is supposed to be a JSON. Before processing the file, it might be wise to check if that file is actually a valid JSON file.

Here is how to check if a file is indeed a valid JSON file:

if jq empty $File 2>/dev/null; then
  ThisFileIsAValidJSONFile="true"
else
  ThisFileIsAValidJSONFile="false"
fi 


(Last update on September 2, 2026 was done by Editor F.)

Leave a Reply

Your email address will not be published. Required fields are marked *