What is JSON: Everything to Know
6 Facts about JSON
- According to its creator, JSON is pronounced like the name Jason. However, most people say the word by emphasizing the letter j and pronouncing “son” like the “mon” in “monster.”
- JSON is an internationally defined standard, with definitions by two different standards organizations (ISO and ECMA).
- The prototype for JSON was created for a virtual card game called Cartoon Orbit in early 2000.
- JSON stands for JavaScript Object Notation but is a language-independent data format.
- JSON files use the .json file extension.
- JSON does not support comments.
What is JSON: Explained
JSON is a text-only format for storing and exchanging data. The format was initially created by Douglas Crockford at his company State Software in 2000 and 2001. Since that time, it has become a vastly popular format for storing data that needs to be accessed by JavaScript programs or other types of software. Its popularity is reflected in the fact that it is now defined by several international standards, including ISO/IEC 21778:2017 and RFC 8259.
At the heart of JSON’s usefulness is its extreme simplicity. Unlike XML and some other formats, JSON syntax is extremely brief and the data in a JSON object can easily be parsed into data in any number of programming applications. Essentially, all JSON objects are strings where properties are defined and then given values. In addition to strings, JSON supports numbers, other JSON objects, arrays, Booleans (see the biography of George Boole), and null values. Functions, dates, and other undefined data types are not allowed.
JSON objects can be written in any text editor and viewed in any file viewer that opens text files. Once they are saved, JSON files can be accessed by programs written in numerous languages using language-specific parsing functions to retrieve and store data.
How to Use JSON
JSON is easy to use. First, create an empty file in your text editor of choice.
To create a valid JSON object, you only need the properties and values of the data you are representing. For this example, we’ll use data about JavaScript.
- name: JavaScript
- release date: 1995
- type: language
- creator: Brendan Eich
This data would be represented in JSON as follows:
{"name":"JavaScript","release date":"1995","type":"language","creator":"Brendan Eich"}
It’s important to note that dates are not supported by JavaScript. In the example above, the date is a string set off by quotation marks.
Although dates are not supported, not all values need to be strings. JSON objects can also store numbers, other JSON objects, arrays, and Booleans (see the biography of George Boole), as well as the value null. These data types should not be placed in quotation marks when using JSON, or they will be interpreted as strings.
Arrays are defined using square brackets and can contain any type of data supported by JSON (numbers, strings, arrays, JSON objects, Booleans, or null values). Here is an example of a JSON object with an array:
{"names":["John", "Judy", "Ping", "Akiko"]}
The method for accessing JSON files varies by programming language and environment. To determine how best to store and access them, refer to the documentation for the language you are using.
How to Learn JSON
With its wide variety of applications in many languages, learning JSON can be a good way to increase your computer programming capabilities.
Fortunately, JSON is easy to learn. The syntax is straightforward and simple, especially if you already know JavaScript. Even for those who have never needed to use objects in JavaScript (or use JavaScript at all), JSON is easy to pick up as all you really need to learn are a few simple rules.
The bulk of learning JSON is learning how to use it in your programming language of choice. Although nearly all programming languages support JSON, each has a slightly different implementation. This means that to be truly proficient in JSON you need to not only learn the format’s syntax but also how to parse it in the language that will be using the data.
There are many free JSON tutorials online and numerous books that take a deep dive into the subject. Here are a few of the best:
- Learn JSON at W3 Schools
- Learn JSON at Mozilla
- Introduction to JSON by Lindsay Bassett (O’Reilly Books)
- JSON Quick Syntax Reference by Wallace Jackson (Apress Books)
JSON Release History
JSON was first released in 2001 and its syntax has not changed since then. As a data format rather than a programming language, it also has no “release history” as such. However, there are several standards that define the format and how it can be used.
RFC 4627
In 2006, the Internet Engineering Task Force (IETF), released a Request for Comments (RFC) document, RFC 4627, describing JSON’s basic capabilities, encoding, parser functionality, and security considerations.
ECMA 404
ECMA 404, released in 2013, was the first official standard defining JSON syntax.
A second edition of the ECMA 404 standard was released in December 2017.
ISO/IEC 21778:2017
Also in 2017, the International Standard Organization (ISO) and (IEC) released ISO/IEC standard 21778:2017 to define the syntax for JSON.
The Difference between JSON and YAML
JSON is only one of many different data interchange formats, including XML, RSS, and others. Another commonly used format, YAML, is especially interesting because it is so similar to JSON that all valid JSON files are also valid YAML files.
There are several significant differences between JSON and YAML, primarily based on things that are supported in YAML but not in JSON. The most important of these are listed below:
- YAML supports comments, while JSON does not
- JSON strings require quotation marks, while YAML strings do not
- YAML supports mapping and anchors, while JSON does not
Although YAML has more features, JSON is still an incredibly useful format because of its streamlined nature and simplicity.