Improved JSON response serialization (Fixes #2).