Check if data is returned before writing json and html