Issue 597: Export database as JSON

No, you can't leave it like this, it's still a backwards-incompatible behavior change. And reverting this new code will also fix the complexity problem.