Total Pageviews

Thursday 1 February 2018

Difference between JSON and JSONP?

In most of the interviews of any programming or scripting language, there is one question which can come across and that is “What is the difference between JSON and JSONP?”

It looks like a simple question but most of us doesn’t aware about this much about the same. So below in the table I have just tried to summarize the differences between the JSON and JSONP.

S.No.
JSON

JSONP

1

JavaScript Object Notation

JSON with extra code

2

JSON is used to storing and exchanging data between a browser and server

JSONP is used to storing and exchanging data between a browser and server

3

JSON is used for same origin or same domain requests

JSONP is used for cross domain requests

4

JSON doesn’t allow any callback function

JSONP allows us to specify a callback function that is passed with JSON object. This allows us to bypass the same origin policy and load JSON from an external server

5

JSON cannot be returned in our script file.

JSONP loads the JSONP script into the head of the DOM so that we can access the information as it loaded from our own domain.

6

JSON cannot request JSON data from another domain via AJAX due to same-origin policy

JSON can be called via AJAX using JSONP

7

JSON ex : {"name":"test","id":15, “class”:”new”};

JSONP ex : functionCall ({"name":"test","id":15, “class”:”new”});

8

JSON is in the form of txt file or quoted into single quotation mark following curly braces

JSONP is in the form of script as shown in above row


References:

Microsoft Logo using flexbox and Reactjs

 <!DOCTYPE html> <html> <head>     <script src="https://unpkg.com/react@18/umd/react.development.js" crossori...