Refactored out JSON serialization.