I need to parse JSONP messages in .NET and find JSON in those messages. Is there any up to date specification describing a valid JSONP message?
I found this blog post (from 2005) by Bob Ippolito specifying the first JSONP proposal, where a JSONP message could contain almost any JavaScript code.
I also found a probably more recent specification on json-p.org allowing only function calls to functions specified in a requesting URI parameter named callback.
Finally Wikipedia says:
While the padding (prefix) is typically the name of a callback
function that is defined within the execution context of the browser,
it may also be a variable assignment, an if statement, or any other
JavaScript statement. The response to a JSONP request (namely, a
request following the JSONP usage pattern) is not JSON and is not
parsed as JSON; the returned payload can be any arbitrary JavaScript
expression, and it does not need to include any JSON at all. But
conventionally, it is a JavaScript fragment that invokes a function
call on some JSON-formatted data.
So is there any global definition what makes a valid JSONP response and what JavaScript constructs are allowed? Should I expect any JavaScript code, because that is what current browsers accept (because it has application/javascript content type)?
As JSONP is a pattern rather than a language (as is the case with JSON), there is no standard.
It’s name implies that you’ll get a valid JSON object wrapped in a function call.
Indeed, the “specification” which tells you what will be included in the response should be something for the API you’re subscribing to to document.