JavaScript and JSON Essentials by Sai Srinivas Sriparasa is a useful beginner-level book for developers looking for an introduction to JSON. In about 100 pages, it covers the basic topics related to JSON with plain-English explanations. I liked Chapter 5, Cross-domain Asynchronous Requests which covers JSONP or JSON with Padding among all the chapters.
There are more Web APIs in the comprehensive directory that the website ProgrammableWeb maintains which are JSON based now than other formats which indicates the importance of JSON.
I wish there were more code samples covering public JSON-based Web APIs & their usage
Excerpts and samples of the explanations I liked:
JSON is text-based, lightweight, and a human-readable format for data exchange between clients and servers. JSON is derived from JavaScript and bears a close resemblance to JavaScript objects, but it is not dependent on JavaScript. JSON is language-independent, and support for the JSON data format is available in all the popular languages, some of which are C#, PHP, Java, C++, Python, and Ruby.
JSON can be used in web applications for data transfer. Prior to JSON, XML was considered to be the chosen data interchange format.
JavaScript engine in the browser handles JSON parsing
A MIME (Multipurpose Internet Mail Extensions) type is an Internet media type, which is a two-part identifier for content that is being transferred over the Internet. The MIME types are passed through the HTTP headers of an HTTP Request and an HTTP Response. The MIME type is the communication of content type between the server and the browser. In general, a MIME type will have two or more parts that give the browser information about the type of data that is being sent either in the HTTP Request or in the HTTP Response. The MIME type for JSON data is application/json. If the MIME type headers are not sent across the browser, it treats the incoming JSON as plain text.
JSON keys and values have to be enclosed in double quotes, if either are enclosed in single quotes, we will receive an error.
JSON supports six datatypes: strings, numbers, Booleans, arrays, objects, and null.
Arrays and null values are objects in JavaScript.
The "X" in AJAX was originally considered to be XML, but today it can be any data interchange format, such as XML, JSON, text file, or even HTML
A callback is a set of scripts that will be waiting for a response and will be fired on receiving that
response.
The jQuery done callback function is fired when the server sends a response back to our asynchronous request. done is the same as XMLHttpRequest object's readyState=4 and request.status=200. XMLHttpRequest object is responsible for making an asynchronous request.
The same domain policy is a security measure followed by web browsers in order to prevent one domain from accessing information on another domain. Web applications use cookies to store
basic information about a user's session so as to provide an intuitive user experience when the user requests the same web page another time or requests a different web page on the same domain. To prevent an external website from stealing this information, web browsers follow the same origin policy.
In order to get around the same origin policy, we will be using JSONP, which is JSON with Padding. One exception under the same origin policy is the <script> tag so scripts can be passed across domains. JSONP uses this exception in order to pass data across domains as a script by adding padding to make the JSON object look like a script. In JavaScript, when a function with a parameter is invoked, we call the function and add a parameter. With JSONP, we pass the JSON feed as a parameter to a function; thereby, we pad our object into a function callback. This function into which the JSON feed has been padded has to be used on the client-side to retrieve the JSON feed.
..simple things that might break JSON, such as ignoring double quotes, or a trailing comma on the last item in the JSON object, or the wrong content-type being sent over by the web server.
JSONLint is not just an online JSON validator, it also helps us format JSON and makes it look pretty.
A dependency manager is a software program that keeps track of all the necessary base programs that are required for a dependent program to run.
Node.js is a popular software platform that uses the JSON data format for tracking dependencies. Node Packaged Modules (NPM) is the package manager that developers use for installing and integrating external modules into their code.
On the same line as dependency managers, JSON is also used to store metadata for software projects. Prior to JSON becoming popular, the configurations and metadata were either stored in a text file or in language-specific files, such as config.php for PHP, config.py for Python, and config.js for JavaScript.
We can also use JSON to store metadata for dependency managers, package managers, configuration managers, and schema data stores.
No comments:
Post a Comment