-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsplitJSON.js
65 lines (56 loc) · 1.43 KB
/
splitJSON.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const fs = require("fs");
const readJsonFile = (filePath) => {
const rawData = fs.readFileSync(filePath);
return JSON.parse(rawData);
};
const writeJsonFile = (filePath, data) => {
const jsonData = JSON.stringify(data, null, 2);
fs.writeFileSync(filePath, jsonData);
};
const filterFields = (data) => {
return data.map(
({
MULTIVERSEID,
ARTIST,
FLAVOR,
FOREIGN_NAMES,
PRINTINGS,
ORIGINAL_TEXT,
ORIGINAL_TYPE,
SET,
SET_NAME,
NUMBER,
LANGUAGE,
GAME_FORMAT,
WATERMARK,
TIMESHIFTED,
HAND,
LIFE,
RELEASE_DATE,
STARTER,
RESERVED,
SOURCE,
LEGALITY,
LAYOUT,
RULINGS,
BORDER,
...rest
}) => rest
);
};
const splitJsonFile = (originalFilePath, numberOfFiles) => {
let data = readJsonFile(originalFilePath);
// Filter out the unwanted fields
data = filterFields(data);
const itemsPerFile = Math.ceil(data.length / numberOfFiles);
for (let i = 0; i < numberOfFiles; i++) {
const start = i * itemsPerFile;
const end = start + itemsPerFile;
const slicedData = data.slice(start, end);
const newFileName = `split_data_part_${i + 1}.json`;
writeJsonFile(newFileName, slicedData);
}
};
const originalFilePath = "public/mtg_cards.json";
const numberOfFiles = 15;
splitJsonFile(originalFilePath, numberOfFiles);