-
Notifications
You must be signed in to change notification settings - Fork 0
/
json.js
39 lines (33 loc) · 900 Bytes
/
json.js
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
// Import
const fs = require("fs");
// Test Schema
const ali = {};
ali["id"] = 1001;
ali["name"] = "ALI";
ali["salary"] = 50001;
console.log(`Ali name is: ${ali["name"]}`);
// Test Schema
const reza = {};
reza["id"] = 1002;
reza["name"] = "REZA";
reza["salary"] = 50002;
console.log(`Reza name is: ${reza["name"]}`);
// Test Schema
const javad = {};
javad["id"] = 1003;
javad["name"] = "JAVAD";
javad["salary"] = 50003;
console.log(`Javad name is: ${javad["name"]}`);
// Test Schema
const employees = [];
employees.push(ali);
employees.push(reza);
employees.push(javad);
console.log(`Data: ${employees}`);
const bytes = JSON.stringify(employees);
console.log(`JSON: ${bytes}`);
// Save employees to file
fs.writeFileSync("employees.json", bytes);
// Save employees from a file/or bytes
const load_employees = JSON.parse(bytes);
console.log(`Read data from JSON: ${load_employees.toString()}`);