-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaScript_thirteenth.html
More file actions
39 lines (35 loc) · 1.43 KB
/
JavaScript_thirteenth.html
File metadata and controls
39 lines (35 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Working with JSON</title>
</head>
<body>
<h1>JSON</h1>
<p>JSON is a text-based, language-independent data interchange format. A JSON object contains data in the form of key/value pair. The keys are strings and the values are the JSON types. Keys and values are separated by colon. Each entry (key/value pair) is separated by comma. The { (curly brace) represents the JSON object.</p>
<script>
let obj = {
name: "Saurav",
roll: "17CH30049",
cgpa: 8.59,
college: "IIT KGP",
hall: "RP",
places: ["Delhi", "Kota", "Muzaffarpur", "Kharagpur"],
status: true
};
console.log(obj);
// converting obj to JSON string //
let jsonString = JSON.stringify(obj);
console.log(jsonString);
console.log(typeof(jsonString)); // string
// we can play with this string//
jsonString = jsonString.replace("Saurav", "Nishant");
console.log(jsonString);
// getting back /parsing the JSON string //
let new_obj = JSON.parse(jsonString); // takes an argument a valid JSON string //
console.log(new_obj);
</script>
</body>
</html>