Read from database and convert output to JSON