Interesting facts about JSON


JSON stands for JavaScript Object Notation, basically, JSON is frequently used with JavaScript, it was initially meant to be a subset of the JavaScript programming language. However, JSON is a language-independent data format. In this article, we are going to learn about JSON and also their interesting facts with examples.

Introduction to JSON

When data can be transported and stored in a simple format is called JSON, or JavaScript Object Notation. Arrays, objects, names and value pairs, and other data types can all be found in JSON. The format uses quotation marks, brackets, parentheses, semicolons, and colons as punctuation. In JSON, data are expressed as name-value pairs, much like JavaScript object attributes. JSON is a lightweight way of data transport. And also, this language is described as being prototype-based, multi-paradigmatic, and dynamic. We need to use JSON whenever data is sent from a server to a web page.

Facts of JSON

Here we are going to discuss so many interesting facts about JSON with explanations and examples. Following are the interesting facts about JSON −

  • Initially, JSON was considered a subset of the JavaScript programming language. (especially the December 1999 release of Standard ECMA-262, Third Edition).

  • JSON was generated from JavaScript, numerous programming languages now have code that may be used to call and interpret JSON-format data. It is a data format that is not language specific. The accepted Internet media type for JSON is application/JSON. The .json extension is used for JSON filenames.

  • Douglas Crockford was the first to define and popularise the JSON format. In April 2001, Douglas Crockford and Chip Morningstar sent the first JSON message.

  • Crockford inserted a phrase to the JSON license declaring that "The Software Shall Be Used for Good, Not Evil." On the other side, because free software and open-source software often imply no limits on the purpose of usage, this section caused licensing compatibility issues of the JSON license with other open-source licenses.

  • The syntax of the JSON format is comparable to that of the JavaScript object creation code. This makes it simple for a JavaScript program to turn JSON data into JavaScript objects. JSON data may be utilized by any programming language and is easily transferrable between machines because it is merely in text format.

  • There is a trading game of children's digital assets called Cartoon Orbit at Communities.com (the State co-founders had all previously worked at this company) for Cartoon Network used a plug-in of browser-side with a custom messaging system to change DHTML components. This was the beginning phase of the JSON libraries.

  • The request will typically fail silently if the JSON file has a syntax problem. JSON data shouldn't be frequently edited by hand for this reason. The data exchange format JSON has higher grammar requirements than JavaScript's object literal notation. For instance, all strings in JSON representations, whether they are values or properties, need to be contained in double quotes

  • The JSON string is decrypted by JavaScript running in the user's browser, which then displays the product data on the page.

Working with JSON

As we have seen that JSON is a type of object in the JavaScript programming language that stores the data in form of a string literal and ends with the .json extension. The object of JSON stores the data in a key-value format that is covered in curly braces just like the objects of JavaScript. Let’s see an example to get a better idea of JSON code −

{
   "key1" : "pair1",
   "key2" : "pair2",
   "key3" : {
      "sub-key1" : "opp_value",
      "sub_key2" : "opp_value",
   },
   "key4" : {
      "sub-key1" : "opp_value",
      "sub_key2" : "opp_value",
   },
   "key5" : "pair5",
}

In the above code of JSON, we can see that there are five key pairs, in which keys are in the form of simple strings and pairs can be strings or other objects that could be anything like an array, string, etc. All the key pairs are separated by the comma and covered under the curly braces.

Any data can be stored in this manner and can be passed or shared in an easy manner with this format.

Storing Arrays in JSON

We have seen the simple code to write the JSON object, now let’s see how the user can store an array in a JSON object −

{
   "key1" : "pair1",
   "key2" : "pair2",
   "key3" : {
      "sub-key1" : "opp_value",
      "sub_key2" : "opp_value",
   },
   "key4" : [
      "sub-key1" : "opp_value",
      "sub_key2" : "opp_value", object1, object2
   ],
   "key5" : "pair5",
}

In the above code, we can see in the fourth key there is an array stored instead of another object and this is supported by the json.

Difference between JSON and XML

Both JSON and XML are used to store the data and share or transport it and both are really good at their own league, let’s see some of the points that make the difference between both of them −

  • JSON is quite easy to learn as compared to XML as it is not straight forward to work with.

  • As JSON is just a straight string that contains the data in the form of key pairs makes it easy to read and write the javascript objects easy on the other hand XML is hard to read and write

  • JSON is data-oriented and works in that way while XML is document-oriented.

  • JSON is not secure because it is just data-oriented while XML is quite secure as compared to JSON.

  • Arrays are not supported by XML while JSON provides the facility to support the arrays.

Similarities between XML and JSON

We have seen some differences between JSON and XML, now let’s move to see some common things between both of them −

  • Due to the fact that they both contain text that can be read by people, XML and JSON are both self-descriptive

  • Both JSON and XML support hierarchical organization. When we talk about hierarchy, we mean values enclosed within values.

  • Formats for exchanging data as formats for exchanging data, JSON and XML are supported by a wide range of programming languages.

  • Both formats may be processed quickly and simply.

  • Retrieval: Data in both forms can be retrieved using HTTP requests. The data can be retrieved using the GET, PUT, and POST methods.

Conclusion

In this article, we learned about JSON and also their interesting facts with examples. JSON stands for JavaScript Object Notation, basically, JSON is frequently used with JavaScript, it was initially meant to be a subset of the JavaScript programming language. Arrays, objects, names and value pairs, and other data types can all be found in JSON. The format uses quotation marks, brackets, parentheses, semicolons, and colons as punctuation.

Updated on: 02-Mar-2023

440 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements