Working JSON encoding (including hacks)