Refactor JSON serialization.