Data Structures & Algorithms

What is JSON

JavaScript Object Notation (JSON) is a data format commonly used to exchange data between the client and server end of a web application. JSON is arguably the most widely used data exchange format on the web. With the growing number of web developers, there is a growth in the number of people looking to understand this format and be able to work efficiently with JSON data. This article is targeted at those individuals to explain the basics of JSON in a simple way.

What is JSON

JSON, simply put, is a data format following a specific syntax to define data objects. It is written in human-readable, structured text format. The JSON file format is used for recording and interchanging data among various users (humans or other software applications), but most commonly, JSON file format is used to interchange data between the client (front end) and server (back end) of a web application. It is pronounced like the name Jason, and its files can be stored on your computer with a .json extension.

It is extremely lightweight and the most widely used format for most of the existing web applications and web services. Other formats that compete with JSON are “Extensible Markup Language” (XML) and “Yet Another Markup Language” (YAML).

JSON can be used anywhere today. Apart from its purpose, JSON also supports many different databases such as MySQL and MongoDB. Although JSON was created with JavaScript in mind, it is independent of any programming language and is used widely by most platforms today. Microsoft Visual Studio has many plugins and packages that can be used to serialize and deserialize JSON data, such as newtonsoft.json.

How and why was this format created

The creation of JSON is mostly attributed to Douglas Crockford in the early 2000s. Somewhere in 2002, he first registered the domain json.org. Before JSON, browsers were dumb, and all the heavy processes were conducted at the server. With the increase in the computational prowess of personal computers and the desire to enhance the overall user experience, there was a need to design a stateless data communication protocol between browsers and servers.

What is the syntax of the JSON format

JSON data format is simple. Its simplicity is its reason for interoperability. It follows the same structure that is followed by JavaScript objects. It is specified in the form of ‘attributes’ and ‘values’. The data is enclosed in curly brackets ({}). Each attribute is separated from the value a colon (:) and is provided as strings in quotation marks (“”) where each pair is separated from the next by a comma (,). Arrays in JSON format are bounded by square brackets ([]), and array elements have separated a comma (,).

JSON format supports most data types; these include Numbers (integers, decimals, and exponents), Strings, Booleans, Arrays of these data types or other objects (attribute: value pairs). The format uses Unicode standard UTF-8 for the purpose of interoperability; backslash escape is a preferred choice. It even supports emojis, such as using an escape “\U+1F600,” a grinning face emoji can be transmitted.

For example, a JSON file containing data of various individuals, describing their suitability for the development of software could be:

{
    "FirstName":    "John",
    "LastName":     "Doe",
    "Age":      28,
    "ApptituteScale":   8,
    "MathematicalSkill":    6,
    "IsPassionate":     true,
    "ProgrammingLanguages": [
        {
            "Name":     "Java",
            "SkillLevel": 8
        },
        {
            "Name":     "Python",
            "SkillLevel": 5
        },
        {
            "Name":     "C++",
            "SkillLevel": 7
        }
    ]
}

What are some useful tools to work with JSON data?

Due to the wide acceptance of JSON format in most databases, programming tools, and accessible and readable formatting, there are many online and offline tools to create, validate, and use JSON data for various applications. Some most widely used tools are:

  • JSONLint: This is an online tool that can be used to validate your JSON data.
  • Stack.hu: This online tool structures your data into a tree to better understand your data.
  • Convertcsv.com: This online tool can convert your data directly into a CSV format. This allows users to open JSON data in Microsoft excel.
  • SQLizer: This tool can convert JSON data into SQL. This is quite handy for transferring data to any SQL database.

Conclusion

JSON is one of the most widely used applications to exchange the data between client and server, which is also lightweight, easily readable, and independent of any computer language. In this article, we have explained some key points regarding JSON. Starting with the detailed explanation of JSON, later this article has also covered the details of JSON format and some useful tools that can work well with JSON data

About the author

Taimoor Mohsin