Professional Documents
Culture Documents
Web Dev Assignment 4 @abhi
Web Dev Assignment 4 @abhi
Name :- Abhinav
Roll No:- HU21CSEN0500083
Task 1: Read a JSON object and display its content in an HTML table
Code :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JSON to HTML Table</title>
<style>
table {
border-collapse: collapse;
width: 100%;
}
th, td {
border: 1px solid black;
padding: 8px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
</style>
</head>
<body>
<table id="jsonTable">
<thead>
<tr>
<th>Key</th>
<th>Value</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<script>
// JSON Object
var jsonObject = {
"Name": "John",
"Age": 30,
"City": "New York"
};
Output :
Task 2: Read JSON Array and convert it into a string using the stringify
function
Code :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JSON Array to String</title>
</head>
<body>
<div id="jsonArrayDisplay"></div>
<script>
// JSON Array
var jsonArray = [
{ "name": "John", "age": 30 },
{ "name": "Alice", "age": 25 },
{ "name": "Bob", "age": 35 }
];
Output :