Returns json encoded data from the database