{"id":28625,"date":"2022-03-12T13:44:21","date_gmt":"2022-03-12T13:44:21","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=28625"},"modified":"2022-12-23T06:47:51","modified_gmt":"2022-12-23T06:47:51","slug":"what-is-json-and-how-it-works","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/what-is-json-and-how-it-works\/","title":{"rendered":"What is JSON and How it works?"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"418\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/An-Introduction-to-JSON.jpg\" alt=\"\" class=\"wp-image-28627\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/An-Introduction-to-JSON.jpg 800w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/An-Introduction-to-JSON-300x157.jpg 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/An-Introduction-to-JSON-768x401.jpg 768w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p>In a world inundated with data, it is becoming more important to know how to work with a variety of data. As programmers, we need to be able to transfer our populated data structures from any language we choose to a format that is recognizable and readable by other languages and platforms. Fortunately for us, there exists such a data-exchange format.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is JSON?<\/h2>\n\n\n\n<p>JSON, or JavaScript Object Notation, is a popular, language-independent, standard format for storing and exchanging data. Adopted by\u00a0ECMA International, an industry association founded in 1961 to standardize information and communication systems,\u00a0Json\u00a0has become the de facto standard that facilitates storing and sending data between all programming languages.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Advantages of JSON<\/h2>\n\n\n\n<p>JSON is easy to learn and simple to read and understand. Plus, its format is text-only, so it can be easily sent across servers. In fact, web applications prefer JSON over XML as it is faster and easier to parse. Some other benefits of JSON are as follows:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. Fast and efficient<\/h3>\n\n\n\n<p>The syntax of JSON is quite simple and self-describing at the same time. Even the applications that don\u2019t know which type of data to expect can interpret JSON. Actually, its syntax is inspired by JavaScript greatly, thus the similarity. But it is still independent and can be used separately. The syntax is quite straightforward, too. The data is in the key\/value pair, where a colon separates the field name and value.<\/p>\n\n\n\n<p>Additionally, JSON is lightweight and compact. Therefore, the same data in JSON will be almost two-thirds of the XML. This is to say, using only JSON, you can perform the same functions as XML with fewer characters. The obvious advantage of this is that it results in faster execution. Overall, this makes JSON quick and efficient in performing functions. The other benefit of uncomplicated syntax is that it simplifies data access.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. Responsive<\/h3>\n\n\n\n<p>JSON is an easy-to-parse data format. You don\u2019t need any additional code for parsing, either. The perk of JSON server-side parsing is that it increases responsiveness. That way, the clients can get faster responses to their queries. For this reason, JSON is widely adopted as a standard data exchange format. Other than this, if you are working with an object-oriented system, JSON can be your go-to as it can be easily mapped. The reason for easy mapping is that it is data-oriented, whereas its counterpart XML is document-oriented.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. Key\/Value pair approach<\/h3>\n\n\n\n<p>The JSON object is rendered in curly brackets, with the key\/value pairs inside the space. The key, as well as value, are wrapped in double quotation marks (\u201d \u201c). They are separated by a colon (:) and commas (,), i.e., those characters divide these pairs. The key\/value approach utilized by JSON makes it a simple data format. It also streamlines write and read operations.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4. Data sharing<\/h3>\n\n\n\n<p>Out of several functions of JSON, the notable one is sharing of data. It is used to establish a connection between front-end and back-end languages for sharing data. Firstly, the front-end language is converted to JSON text, which is known as serialization. Then, the JSON text is converted to programming data, which is known as deserialization. The process of serialization and deserialization is quite fast in JSON, eventually promoting sharing of structured data.<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\"  id=\"_ytid_88339\"  width=\"760\" height=\"427\"  data-origwidth=\"760\" data-origheight=\"427\" src=\"https:\/\/www.youtube.com\/embed\/whNFPBEI-wM?enablejsapi=1&#038;autoplay=0&#038;cc_load_policy=0&#038;cc_lang_pref=&#038;iv_load_policy=1&#038;loop=0&#038;rel=1&#038;fs=1&#038;playsinline=0&#038;autohide=2&#038;theme=dark&#038;color=red&#038;controls=1&#038;disablekb=0&#038;\" class=\"__youtube_prefs__  epyt-is-override  no-lazyload\" title=\"YouTube player\"  allow=\"fullscreen; accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Disadvantages of JSON<\/h2>\n\n\n\n<p>The compact form of JSON has its downsides. The developers have to follow the restrictive specifications of the JSON. Otherwise, it can lead to complications in the implementation of the JSON parser. This has an impact on the writability and readability of the code to a certain extent. The following are other drawbacks of JSON:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. No date data type<\/h3>\n\n\n\n<p>JSON includes data types such as string, number, object, array, boolean, and null. But it skips the date data type. The lack of the date data type in JSON forces developers to look for an alternative. One way to represent the date is using the string data type. However, this can create discrepancies in the formatting. Also, changing the JSON data into another format is tedious. Whereas in XML, you can easily achieve this using the XSLT template. The built-in support for format change in XML is quite beneficial, but there is no similar support in JSON.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. Verbose<\/h3>\n\n\n\n<p>Verbosity on this list might come as a surprise, considering we have emphasized how easy and compact JSON code is. Surely, JSON uses fewer characters than its counterparts. But the same feature becomes a drawback when you are working on special-purpose projects. The reason is: JSON code isn\u2019t concise, which defeats the purpose of using it. In these cases, you might want to explore other data formats that will give you the efficiency and results you are looking for.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. Lack of comments<\/h3>\n\n\n\n<p>The comments are essential in understanding the code. You can use comments in JSON but with limitations. This is to say, you\u2019ll have a hard time clarifying the data in the data itself. Also, comments are not allowed by some JSON libraries as inputs. In such cases, you will need to use the preprocessor to remove those comments. However, this leads to additional work of editing in order to parse the file.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4. Less secure<\/h3>\n\n\n\n<p>Even though the majority of internet browsers provide native JSON support, there are still some that don\u2019t. When faced with such a situation, the eval() function is used. It parses JSON into JavaScript objects. But there is a possibility that using this function can make your application less secure. It also leaves you vulnerable to attacks. The problem arises especially when you are taking inputs from users. In these situations, if malicious scripts are entered, they can promptly wreak havoc.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"604\" height=\"407\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/json-introduction.png\" alt=\"\" class=\"wp-image-28628\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/json-introduction.png 604w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/03\/json-introduction-300x202.png 300w\" sizes=\"auto, (max-width: 604px) 100vw, 604px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">JSON Data Types<\/h2>\n\n\n\n<p>A JSON data type must be one of the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>string (double-quoted)<\/li><li>number (integer or floating point)<\/li><li>object (name-value pair)<\/li><li>array (comma-delimited)<\/li><li>boolean (true or false)<\/li><li>null<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Common Uses of JSON<\/h2>\n\n\n\n<p>JSON is heavily used to facilitate data transfer in web applications between a client, such as a web browser, and a server. A typical example where such data transfer occurs is when you fill out a web form. The form data is converted from HTML to JavaScript objects to JSON objects and sent to a remote web server for processing. These transactions could be as simple as entering a search engine query to a multi-page job application.<\/p>\n\n\n\n<p>When companies make their data public for other applications, like Spotify sharing its music library or Google sharing its map data, the information is formatted in JSON. This way, any application, regardless of language, can collect and parse the data.<\/p>\n\n\n\n<p>Some of the popular web APIs that utilize JSON in data exchanges are:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/developers.google.com\/maps\/documentation\/geocoding\/start\" target=\"_blank\" rel=\"noreferrer noopener\">Google Maps<\/a><\/li><li><a href=\"https:\/\/docs.microsoft.com\/en-us\/linkedin\/shared\/integrations\/people\/profile-api\" target=\"_blank\" rel=\"noreferrer noopener\">LinkedIn Profile API<\/a><\/li><li><a href=\"https:\/\/developers.google.com\/identity\/protocols\/oauth2\/service-account\" target=\"_blank\" rel=\"noreferrer noopener\">Google Auth  2.0 Authentication<\/a><\/li><li><a href=\"https:\/\/developers.facebook.com\/docs\/messenger-platform\/reference\/send-api\" target=\"_blank\" rel=\"noreferrer noopener\">Facebook Social Graph API<\/a><\/li><li><a href=\"https:\/\/developer.spotify.com\/documentation\/web-api\/\" target=\"_blank\" rel=\"noreferrer noopener\">Spotify Music Web API<\/a><\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Introduction In a world inundated with data, it is becoming more important to know how to work with a variety of data. As programmers, we need to be able to transfer our populated data structures from any language we choose to a format that is recognizable and readable by other languages and platforms. Fortunately for&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_joinchat":[],"footnotes":""},"categories":[2],"tags":[],"class_list":["post-28625","post","type-post","status-publish","format-standard","hentry","category-uncategorised"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/28625","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=28625"}],"version-history":[{"count":1,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/28625\/revisions"}],"predecessor-version":[{"id":28629,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/28625\/revisions\/28629"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=28625"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=28625"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=28625"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}