Try jsonlint:
sudo apt install jsonlint
The basic usage syntax is
jsonlint YOUR-FILE.JSON
You find its manual by typing man jsonlint or visiting its online manpage:
An excerpt:
NAME
jsonlint - A JSON syntax validator and formatter tool
SYNOPSIS
jsonlint [-v][-s|-S][-f|-F][-ecodec]inputfile.json...
[...]
OPTIONS
The return status will be 0 if the file is legal JSON, or non-zero
otherwise. Use -v to see the warning details.
[...]
-v, --verbose
Show details of lint checking
-s, --strict
Be strict in what is considered legal JSON (the default)
-S, --nonstrict
Be loose in what is considered legal JSON
-f, --format
Reformat the JSON (if legal) to stdout
[...]
So you can see whether your JSON is valid by checking the return code of jsonlint. You can see it by running echo $? right afterwards (0=OK, 1=invalid), or by evaluating it using &&, || or if.
jsonlintpackage on Ubuntu just now, the installed binary was for some reason calledjsonlint-phprather thanjsonlint. It appears to work correctly, but I had to remember thedpkg-query -Lcommand to figure out what it had actually installed. – Daniel McLaury Nov 28 '18 at 17:39jsonlint-phpfor me as well. Also, the call it expects is a little unusual, with the commands at the end. You usejsonlint-php file.json -vfor verbose outputs, for example. – Stella Biderman Jun 24 '21 at 21:57jsonlint+<tab>and it will finish and add the-phpfor you. – Alexis Wilke Mar 01 '22 at 00:02