It is easy to make mistakes in a JSON file by simply missing a comma or other punctuation mark. A simple command line tool to check the syntax will be helpful to make sure the syntax is correct before even starting to use the file.
This simple tool is written in ruby and uses the “json” rubygem. Any version should be fine. Make sure the gem is installed before attempting to use this tool.
Once the gem is installed, place the contents of the following block into a file (example: /usr/local/bin/jsonlint). Once the file is saved, make the file executable.
Note: If you do not have permission to edit/modify files in this location,
execute the commands using
If you prefer saving the file in a different location, make sure the file is in your PATH or add the location to the PATH.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Tool in action
Here is a simple valid JSON file:
1 2 3 4 5
Running the lint tool against this file gives:
Here is a JSON file that misses a “}”
1 2 3 4
Running the list tool against this file gives: