-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson_generator.php
More file actions
55 lines (45 loc) · 1.65 KB
/
Copy pathjson_generator.php
File metadata and controls
55 lines (45 loc) · 1.65 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
// Number of records to generate
$totalRecords = 100000; // Adjust as needed
$filename = "big_data.json";
// Open file for writing
$file = fopen($filename, "w");
// Start JSON array
fwrite($file, "[");
for ($i = 0; $i < $totalRecords; $i++) {
// Generate random data
$data = [
"id" => $i + 1,
"name" => "User" . ($i + 1),
"email" => "user" . ($i + 1) . "@example.com",
"age" => rand(18, 80),
"phone" => "+1-555-" . rand(1000000, 9999999),
"address" => [
"street" => rand(100, 9999) . " Main St",
"city" => "City" . rand(1, 100),
"state" => "State" . rand(1, 50),
"zipcode" => rand(10000, 99999),
"country" => "USA"
],
"status" => (rand(0, 1) == 1) ? "active" : "inactive",
"balance" => round(rand(1000, 100000) / 100, 2),
"ip_address" => rand(10, 255) . "." . rand(0, 255) . "." . rand(0, 255) . "." . rand(0, 255),
"created_at" => date("Y-m-d H:i:s", strtotime("-" . rand(0, 365) . " days")),
"updated_at" => date("Y-m-d H:i:s"),
"preferences" => [
"newsletter" => (rand(0, 1) == 1),
"notifications" => (rand(0, 1) == 1),
"theme" => (rand(0, 1) == 1) ? "dark" : "light"
]
];
// Convert array to JSON string
$jsonData = json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
// Write to file with comma if not the last record
fwrite($file, $jsonData . ($i < $totalRecords - 1 ? "," : ""));
}
// End JSON array
fwrite($file, "]");
// Close the file
fclose($file);
echo "JSON file '$filename' generated successfully!\n";
?>