Site Loader

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.

Best services for writing your paper according to Trustpilot

Premium Partner
From $18.00 per page
4,8 / 5
4,80
Writers Experience
4,80
Delivery
4,90
Support
4,70
Price
Recommended Service
From $13.90 per page
4,6 / 5
4,70
Writers Experience
4,70
Delivery
4,60
Support
4,60
Price
From $20.00 per page
4,5 / 5
4,80
Writers Experience
4,50
Delivery
4,40
Support
4,10
Price
* All Partners were chosen among 50+ writing services by our Customer Satisfaction Team

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:

  • The names should be meaningful. For example, you could use the letter x to represent the first name and the letter y to represent the last name, but x and y do not say what they represent and are not meaningful. Therefore, they are not recommended in JSON naming convention.

  • Names should be camel case. Camel Case is writing compound words where each new word begins with a capital letter. In the above example, firstName is a compound word where the second word Name has a capital N.

    And to represent the feather color of parrots, we could write this in camel case, as follows: featherColorParrots.

  • The first letter has to be one of: letter, underscore, or $ sign. So for example, the name 4Corners is not valid, instead this has to be written as fourCorners, or FourCorners.

  • Characters following the first character can be one of: letter, digit, underscore, or $ sign. So for example, to represent the length of 2 corners of a book shelf, some of the ways to represent the name would be:
  1. length2CornersBookShelf
  2. Length2CornersBookShelf
  3. length_2_Corners_Book_Shelf
  4. length_2_Corners_Book_Shelf$
  5. $length_2CornersBookShelf
  6. _length2Corners_BookShelf

JSON Array

A JSON array is a collection of JSON name/value pairs. A JSON array is used when there is more than one name and value pairs, f. For example, an array would be used to represent the first and last names of 2 or more employees in an office.

A JSON array has the following format:

  • begin with left square bracket [
  • end with right square bracket ]
  • the array is given a name and the name is enclosed in double quotation marks
  • the name/value pair follows the format of JSON Objects for name and value

Example:Define a JSON array to represent the first and last names of 3 employees in an office.Solution:"employees":[{"firstName":"John", "lastName":"Doe"},{"firstName":"Ann","lastName":"Smith"},{"firstName":"Peter", "lastName":"Pan"}]

Style Guide for JSON Arrays

Since a JSON array is used to represent multiple objects, the array name should be plural. In the above example of employee names, it is not recommended to use the name ’employee’ because the array contains more than one name/value pair.

Lesson Summary

JSON is a format to exchange data between the server and the browser as name and value pairs.

The name is the variable name and should be meaningful, and should start with letters, underscore, or the $ sign. The value is the actual value of the data, follows the name, and is separated by a colon. When there is more than one name and value, a JSON array is used to format the data.

The name of the array should be in plural and the array is enclosed within square brackets.

Post Author: admin

x

Hi!
I'm Eric!

Would you like to get a custom essay? How about receiving a customized one?

Check it out