changing messages to JSON object