Complete the JSON serialization function