json:
 - Print stacktrace when handling errors during json generation
 - Some cleanup of error handling