Check the format and return JSON or HTML