JSON | People@UTM, Exercises of Javascript programming

What is JSON? JSON stands for JavaScript Object Notation. This is a lightweight, flexible yet strict method of storing and transmitting data.

Typology: Exercises

2021/2022

Uploaded on 09/27/2022

ekachakra
ekachakra 🇺🇸

4.6

(33)

268 documents

1 / 8

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
What is JSON?
JSON stands for JavaScript Object Notation. This is a lightweight, flexible yet strict method
of storing and transmitting data. Flexible in that the user can create the format and names in
any way they please; strict in the sense that JSON has a strict set of rules for structure.
A JavaScript object is a series of name/value pairs, written in a structured way. The basic
structure is:
{name:value,name:value,name:value}
Generic Rules to be followed while creating a JSON:
JSON Objects should start and end with braces “{ }”.
Key fields are included in the double quotes.
Values are represented by putting “:” colon between them and the keys.
JSON key-value pairs are separated by a comma “,”.
Values can be of any data type like String, Integer, Boolean etc.
Basic JSON file
Let’s assume we have a car object with the following basic properties and their attributes:
Make and Mode = Maruti Suzuki Swift
Make Year = 2017
Color = Red
Type = Hatchback
So, if we want to transfer this data using a JSON file, then the serialization of this data will
create a JSON.
That JSON will look something like this:
pf3
pf4
pf5
pf8

Partial preview of the text

Download JSON | People@UTM and more Exercises Javascript programming in PDF only on Docsity!

What is JSON?

JSON stands for JavaScript Object Notation. This is a lightweight, flexible yet strict method of storing and transmitting data. Flexible in that the user can create the format and names in any way they please; strict in the sense that JSON has a strict set of rules for structure.

A JavaScript object is a series of name/value pairs, written in a structured way. The basic structure is:

{name:value,name:value,name:value}

Generic Rules to be followed while creating a JSON:

 JSON Objects should start and end with braces “{ }”.  Key fields are included in the double quotes.  Values are represented by putting “:” colon between them and the keys.  JSON key-value pairs are separated by a comma “,”.  Values can be of any data type like String, Integer, Boolean etc.

Basic JSON file

Let’s assume we have a car object with the following basic properties and their attributes:

Make and Mode = Maruti Suzuki Swift Make Year = 2017 Color = Red Type = Hatchback

So, if we want to transfer this data using a JSON file, then the serialization of this data will create a JSON.

That JSON will look something like this:

JSON Arrays

 The array starts with a left square bracket “[“and ends with right square bracket “]”.  The values inside the array are separated by a comma.

In order to include the car in the Employee JSON, initially, we need to include a Key as “car” in the JSON.

Something like this:

Once we have added the car key in the employee JSON, we can then pass the value directly to the Car JSON. In this way, we can create a Nested JSON.

Something like this:

Tutorial 2 JQuery to retrieve a .txt file via HTTP, then output it to a web page.

artists.txt

Tutorial 3 Update the Tutorial 2 code to use AJAX method with JQuery to retrieve a JSON file, then output it to a web page.

artists.json Output:

Tutorial 4 HTML Table using Ajax JQuery getJSON method

index.html

employee.json Output:

Tutorial 5 Update Tutorial 4 - getJSON method to get JASON contains imageURL

index.html

employee.json Output: