Add json generator. Close #1

It will surely evolve, but this is a good start.  It can generate
objects and/or arrays at the top level.  Quite a bit of code cleanup
as well.
Improve json test coverage