This is an old revision of the document!


JSON Filetype

JSON files are intended for serializing data objects, but are sometimes used as configuration files. YAML is a superset of JSON, but the differences are minor enough that the YAML lexxer built into Geany still works to appropriately identify structures and for folding large lists.

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:

filetypes.JSON.conf
[styling]
default=default
number=number
string=string
word=word
identifier=identifier,bold
 
[keywords]
primary=true false null
 
[settings]
lexer_filetype=YAML
extension=json
comment_single=
 
[indentation]
width=2
# 0 is spaces, 1 is tabs, 2 is tab & spaces
type=0

Build Commands

For people using Unix, the following will be helpful for checking your JSON files for correctness.

/usr/local/bin/check_json
#!/bin/bash
 
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.

Print/export