Interesting facts about JSON

王林
Release: 2023-09-09 16:01:06
forward
1296 people have browsed it

关于 JSON 的有趣事实

JSON stands for JavaScript Object Notation, basically, JSON is often used with JavaScript and it was originally a subset of the JavaScript programming language. However, JSON is a language-independent data format. In this article, we will learn about JSON and its interesting facts through examples.

JSON Introduction

When data can be transmitted and stored in a simple format, it's called JSON, or JavaScript Object Notation. Arrays, objects, name and value pairs, and other data types can all be found in JSON. This format uses quotation marks, square brackets, parentheses, semicolons, and colons as punctuation marks. In JSON, data is represented as name-value pairs, much like JavaScript object properties. JSON is a lightweight data transmission method. Furthermore, this language is described as prototype-based, multi-paradigm, and dynamic. Whenever data is sent from the server to a web page, we need to use JSON.

JSON Facts

Here we will discuss many interesting facts about JSON with explanations and examples. Here are interesting facts about JSON -

  • Originally, JSON was considered a subset of the JavaScript programming language. (Specifically the standard ECMA-262, third edition published in December 1999).

  • JSON is generated by JavaScript, and many programming languages now have code that can be used to call and interpret JSON formatted data. It is a data format that is not language specific. The accepted JSON internet media type is application/JSON. The .json extension is used for JSON file names.

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

  • Crockford inserted a phrase into the JSON license stating that "this software should be used for good, not evil." On the other hand, since free software and open source software usually mean no restrictions on the purpose of use, this part leads to licensing compatibility issues of the JSON license with other open source licenses.

  • The syntax of the JSON format is comparable to the syntax of JavaScript object creation code. This allows JavaScript programs to easily convert JSON data into JavaScript objects. JSON data can be used by any programming language, and since it is just a text format, it can be easily transferred between machines.

  • Cartoon Network's Communities.com has a children's digital asset trading game called "Cartoon Orbit" (State's co-founders all worked at the company), using a browser plug-in with Customize the messaging system to change DHTML components. This is the beginning of the JSON library.

  • If the JSON file has syntax problems, the request will usually fail silently. Therefore, JSON data should not be manually edited frequently. The data exchange format JSON has higher syntax requirements than JavaScript's object literal representation. For example, all strings in a JSON representation, whether values or properties, need to be enclosed in double quotes

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

Use JSON

As we have seen, JSON is an object type in the JavaScript programming language that stores data in the form of string literals, ending with the .json extension. JSON objects store data in key-value format, enclosed in curly braces just like JavaScript objects. Let’s see an example to better understand 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", }
Copy after login

In the above JSON code, we can see that there are 5 key pairs, where the keys are in the form of simple strings. The key pairs can be strings or other objects, such as arrays, strings, etc. All key pairs are separated by commas and enclosed within curly braces.

Any data can be stored this way and can be passed or shared in a simple way using this format.

Storing Arrays in JSON

We have seen simple code for writing JSON objects, now let us see how users can store arrays in JSON objects -

{ "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", }
Copy after login

In the above code, we can see that the fourth key is stored in an array, not another object, which is supported by json.

Difference between JSON and XML

Both JSON and XML are used to store data and share or transfer data, and both are very good in their own league, let’s look at some of the differences between them -

  • Compared to XML, JSON is very easy to learn because it is not used directly.

  • Since JSON is just a straight string containing data in the form of a key pair, it is easy to read and write JavaScript objects, while XML is difficult to read and write

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

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

  • XML does not support arrays, while JSON provides tools that support arrays.

Similarities between XML and JSON

We've seen some of the differences between JSON and XML, now let's look at some of the things they have in common -

  • Since both XML and JSON contain text that humans can read, they are both self-describing

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

  • Data exchange formats Data exchange formats such as JSON and XML are supported by a variety of programming languages.

  • Both formats can be processed quickly and easily.

  • Retrieval: Both forms of data can be retrieved using HTTP requests. Data can be retrieved using GET, PUT, and POST methods.

in conclusion

In this article, we learned about JSON and its interesting facts through examples. JSON stands for JavaScript Object Notation, basically, JSON is often used with JavaScript and it was originally a subset of the JavaScript programming language. Arrays, objects, name and value pairs, and other data types can all be found in JSON. This format uses quotation marks, square brackets, parentheses, semicolons, and colons as punctuation marks.

The above is the detailed content of Interesting facts about JSON. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!