Added a function to return messages and codes in json