I am looking for information on how to properly parse JSONP messages in .NET and extract the JSON data they contain. Is there a current specification that outlines what constitutes a valid JSONP message?
During my research, I came across a blog post from Bob Ippolito dating back to 2005 which details the initial JSONP proposal allowing various JavaScript code within the JSONP message.
Additionally, I found a more recent specification on json-p.org that permits only function calls to functions specified in a URI parameter named callback
.
Wikipedia also provides insight:
Although the prefix is commonly the name of a callback function defined within the browser's execution context, it can also be a variable assignment, an if statement, or any other JavaScript command. A response to a JSONP request does not consist of JSON and is not treated as such by browsers; the payload can be any JavaScript expression without requiring JSON content. However, conventionally, it is typically a JavaScript snippet that invokes a function with JSON-formatted data.
Given this information, is there a universal definition of what qualifies as a valid JSONP response and which JavaScript constructs are acceptable? Should one anticipate receiving JavaScript code since modern browsers recognize it due to the application/javascript
content type?