Rough attempt at passing data as JSON structure

Hi,

This code is rather primitive and messy, but it does provide a basic way to access the sqlite data on the client.  I'm using it for client-side templating and basic D3 charting.