views:

188

answers:

4

Format wise, file type wise and practical use wise?

A: 

http://bob.pythonmac.org/archives/2005/12/05/remote-json-jsonp/

It sounds like JSONP is a method for grabbing JSON from a different domain. It's not a separate language.

Mark
Separate from what? JSON isn't a language either
nickf
@nickf: Yeah...I was looking for the right word... what would you call it then? "data-interchange format" according to json.org.
Mark
+1  A: 

JSONP is essentially, JSON with extra code, like a function call wrapped around the data. It allows the data to be acted on during parsing.

Delan Azabani
+3  A: 

http://en.wikipedia.org/wiki/JSON#JSONP

JSONP allows you to specify a callback function that is passed your JSON object. This allows you to bypass the same origin policy and load JSON from an external server into the javascript on your webpage.

Squeegy
+6  A: 

JSONP is JSON with padding, that is, you put a string at the beginning and a pair of parenthesis around it. For example:

//JSON
{"name":"stackoverflow","id":5}
//JSONP
func({"name":"stackoverflow","id":5});

The result is that you can load the json as a script file. If you previously set up a function called func, then that function will be called with one argument, which is the json data, when the script file is done loading. This is usually used to allow for cross-site AJAX with JSON data. If you know that example.com is serving json files that look like the one above, then you can use code like this to retrieve it, even if you are not on the example.com domain:

function func(json){
  alert(json.name);
}
var elm = document.createElement("script");
elm.setAttribute("type", "text/javascript");
elm.src = "http://example.com/jsonp";
document.body.appendChild(elm);
Marius