What is JavaScript Object Notation (JSON)?

Instructor: Sudha Aravindan

Sudha has a Doctor of Education Degree and is currently working as a Information Technology Specialist.

In this lesson, learn about JavaScript Object Notation (JSON) which is a subset of the computer programming language, JavaScript. JSON is not a programming language, instead it is a protocol to exchange data on the internet.

History of JSON

When you read the news on your mobile phone or computer, or go shopping online, have you ever wondered how colorful images and a wealth of information are displayed on your screen? Well, behind the scenes are computers and programming languages with rules that define how data should be transmitted between the computer, where the data is stored, and the device on which you are viewing the data. One of the methods of how data is formatted and transferred is JSON.

JSON was originally derived from the JavaScript programming language; later it was developed into a format for exchange of data. The JSON data format works with many different programming languages and is language-independent. JSON defines the rules that should be followed for formatting data that is transmitted between the server and the browser. JSON is not a programming language; it is a protocol that is used to format data.

A server is a computer where data is stored and the browser is a program that connects to the server and displays the data on the web. For example, when we go to the website of any store, we can browse the products the store has to sell, search for products, and even make purchases. The information about the products is saved on a computer known as the web server. We use browsing programs such as Internet Explorer, FireFox, or Chrome to visit websites on the internet, browse for data, and shop online.

JSON is a programming script that is used to transfer data between the server and the web browser. It is not a programming language, instead it is a method to transfer data following a specific structure.

JSON Object

In JSON, an object is a pair that consists of a variable name and the value of the variable. The variable name is simply referred to as name in JSON, and the variable value is referred to as value in JSON. For example if we say that the variable firstName is used to store the first names of staff in an office, and the first name of a staff member is John, this can be represented in JSON notation as: {"firstName":"John"}. If you need to represent both the first and last name of a person, this can be represented as {"firstName":"John", "lastName": "Doe"}.

An object in JSON has the following format:

  • begin with left curly brace {
  • end with right curly brace }
  • each variable name is followed by a colon
  • both the variable name and the value of the variable are enclosed in double quotation marks "
  • each name and value pair is separated by a comma

The variable name, or name, is any name that you can assign to a represent an object. The variable data, or value, is the actual value for that variable.

Example:

Ann wears a size 8 red shoe. Represent this in JSON format.

Solution:

{"shoeColor": "Red", "shoeSize": "8"}

Here the variable names (or JSON names) are shoeColor and shoeSize. The variable values (or JSON values) are Red and 8.

We can represent this using different variable names, for example:

{"shoe_Color": "Red", "shoe_Size": "8"}

Here the names are shoe_Color and shoe_Size. The values are Red and 8.

Style Guide for JSON names

JSON names should be easy to understand. The JSON style guide for names should be followed:

To unlock this lesson you must be a Study.com Member.
Create your account

Register to view this lesson

Are you a student or a teacher?

Unlock Your Education

See for yourself why 30 million people use Study.com

Become a Study.com member and start learning now.
Become a Member  Back
What teachers are saying about Study.com
Try it risk-free for 30 days

Earning College Credit

Did you know… We have over 200 college courses that prepare you to earn credit by exam that is accepted by over 1,500 colleges and universities. You can test out of the first two years of college and save thousands off your degree. Anyone can earn credit-by-exam regardless of age or education level.

To learn more, visit our Earning Credit Page

Transferring credit to the school of your choice

Not sure what college you want to attend yet? Study.com has thousands of articles about every imaginable degree, area of study and career path that can help you find the school that's right for you.

Create an account to start this course today
Try it risk-free for 30 days!
Create an account
Support