Pass tests! Yay! And auto-init db if necessary

This means I finally wrote the to_json function.