- JavaScript and JSON Essentials
- Sai Srinivas Sriparasa
- 565字
- 2021-07-23 15:52:44
Chapter 2. Getting Started with JSON
JSON or JavaScript Object Notation is a very popular data interchange format. It was developed by Douglas Crockford. 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.
Note
JSON is a format and not a language.
JSON can be used in web applications for data transfer. Prior to JSON, XML was considered to be the chosen data interchange format. XML parsing required an XML DOM implementation on the client side that would ingest the XML response, and then XPath was used to query the response in order to access and retrieve the data. That made life tedious, as querying for data had to be performed at two levels: first on the server side where the data was being queried from a database, and the second time was on the client side using XPath. JSON does not need any specific implementations; the JavaScript engine in the browser handles JSON parsing.
XML messages often tend to be heavy and verbose, and take up a lot of bandwidth while sending the data over a network connection. Once the XML message is retrieved, it has to be loaded into memory to parse it; let us take a look at a students
data feed in XML and JSON.
The following is an example in XML:

Let us take a look at the example in JSON:

As we notice, the size of the XML message is bigger when compared to its JSON counterpart, and this is just for two records. A real-time feed will begin with a few thousands and go upwards. Another point to note is the amount of data that has to be generated by the server and then transmitted over the Internet is already big, and XML, as it is verbose, makes it bigger. Given that we are in the age of mobile devices where smart phones and tablets are getting more and more popular by the day, transmitting such large volumes of data on a slower network causes slow page loads, hang ups, and poor user experience, thus driving the users away from the site. JSON has come about to be the preferred Internet data interchange format, to avoid the issues mentioned earlier.
Since JSON is used to transmit serialized data over the Internet, we will need to make a note of its MIME type. 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.
- HTML5+CSS3+JavaScript從入門到精通:上冊(微課精編版·第2版)
- Learning Cython Programming
- Visual FoxPro程序設(shè)計教程(第3版)
- Java Web基礎(chǔ)與實例教程(第2版·微課版)
- Hands-On Image Processing with Python
- Python零基礎(chǔ)快樂學(xué)習(xí)之旅(K12實戰(zhàn)訓(xùn)練)
- NativeScript for Angular Mobile Development
- Cassandra Data Modeling and Analysis
- Effective Python Penetration Testing
- MySQL數(shù)據(jù)庫基礎(chǔ)實例教程(微課版)
- Python機(jī)器學(xué)習(xí)算法與應(yīng)用
- Mastering AWS Security
- Flask Web開發(fā):基于Python的Web應(yīng)用開發(fā)實戰(zhàn)(第2版)
- ROS機(jī)器人編程實戰(zhàn)
- Mastering Machine Learning with R