-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix_json2.cjs
More file actions
51 lines (46 loc) · 1.36 KB
/
fix_json2.cjs
File metadata and controls
51 lines (46 loc) · 1.36 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
const fs = require('fs');
const content = fs.readFileSync('./public/language/fr.json', 'utf8');
const lines = content.split('\n');
// Find the vehicleInsights closing line and remove everything until subscription
let vehicleInsightsEndLine = -1;
let subscriptionStartLine = -1;
for (let i = 0; i < lines.length; i++) {
if (
lines[i].includes('"financialTranslation"') &&
lines[i + 1] &&
lines[i + 1].trim() === '},'
) {
vehicleInsightsEndLine = i + 1;
}
if (lines[i].includes('"subscription"')) {
subscriptionStartLine = i;
break;
}
}
console.log('vehicleInsights ends at line', vehicleInsightsEndLine + 1);
console.log('subscription starts at line', subscriptionStartLine + 1);
if (
vehicleInsightsEndLine >= 0 &&
subscriptionStartLine >= 0 &&
subscriptionStartLine > vehicleInsightsEndLine + 1
) {
console.log(
'Removing lines',
vehicleInsightsEndLine + 2,
'to',
subscriptionStartLine,
);
const newLines = [
...lines.slice(0, vehicleInsightsEndLine + 1),
...lines.slice(subscriptionStartLine),
];
fs.writeFileSync('./public/language/fr.json', newLines.join('\n'));
console.log('Extra lines removed successfully');
// Verify the JSON is valid
try {
JSON.parse(newLines.join('\n'));
console.log('JSON is valid after fix');
} catch (e) {
console.log('JSON is still invalid:', e.message);
}
}