Starting with version 1.25, Geany has a built-in JSON filetype.
Add this to the
filetype_extensions.conf file (
… means existing data):
[Extensions] ... JSON=*.json ... [Groups] ... Misc=JSON ...
And create a new filedef named
filetypes.JSON.conf with the following contents:
For people using Unix, the following will be helpful for checking your JSON files for correctness.
#!/bin/sh if which python >/dev/null ; then python -m json.tool <"$1" 2>&1 >/dev/null \ | sed 's/^\([^:]*\): line \(.*\)/'"$1"':\2: \1/' elif which perl >/dev/null ; then perl -MJSON -e 'local $/;decode_json(<STDIN>);' <"$1" 2>&1 >/dev/null \ |sed 's/^\(.*\) at .e line 1, .STDIN. [^ ]* \([0-9]*\)/'"$1"':\2: \1/;' else echo "No known JSON parsers found" >&2 exit 1 fi
In Geany, go to the Build menu and 'Set Build Commands…' and use
/usr/local/bin/check_json %f as the compile command, and
([^:]+):([0-9]+) as the Error Regular Expression.
Assuming you have Python installed, pretty printing (aka formatting) of JSON is very easy with Geany:
- Python is required (works with Python 2 and 3)
- Configure Geany: Edit→Format→Send Selection to→Set Custom Commands
- In the dialog add a new command and simply use: python -mjson.tool
To use this, select some string in Geany and use Edit→Format→Send Selection to→<your configured command> and Geany will replace the string by the converted version. Alternatively, you can use the shortcut Ctrl-<number> in case your command is one of the first three configured commands. For details, read the documentation about Send Selection to commands.