Is there a way to tell if a feed is XML, JSON, or both?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The best and sure-fire way would be simply to run it through a XML and a JSON parser, and see which one works without generating syntax errors. For example, in PHP, try
json_encode($feed_string)and$xml = new SimpleXMLElement($feed_string);Alternatively, you can just do some simple string checking. All properly-formed XML documents start with
<?xml, while JSON typically starts with{since the feed data is a Javascript object.The samples Google provides as the two feed formats may be helpful:
http://code.google.com/apis/gdata/docs/json.html