--- /dev/null
+#!/bin/sh
+psql sheet -XAt -c "
+ SELECT json_object_agg(coalesce(form, ''), forms)
+ FROM word RIGHT JOIN (
+ SELECT cat id, array_agg(form ORDER BY form) forms
+ FROM word WHERE ref IS NULL GROUP BY cat
+ ) sub USING (id)
+" | sed 's/:/=>/g'