-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate_json.js
More file actions
26 lines (22 loc) · 936 Bytes
/
validate_json.js
File metadata and controls
26 lines (22 loc) · 936 Bytes
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
const fs = require('fs');
const path = require('path');
const filePath = path.join(__dirname, 'source/data/breaches.json');
try {
const fileContent = fs.readFileSync(filePath, 'utf-8');
JSON.parse(fileContent);
console.log('Le fichier JSON est valide.');
} catch (e) {
console.error('Erreur de syntaxe JSON:', e.message);
// Essayer de localiser l'erreur
const positionMatch = e.message.match(/position (\d+)/);
if (positionMatch) {
const position = parseInt(positionMatch[1], 10);
const fileContent = fs.readFileSync(filePath, 'utf-8');
const context = 100;
const start = Math.max(0, position - context);
const end = Math.min(fileContent.length, position + context);
console.error(`\n--- Contexte de l'erreur (autour de la position ${position}) ---`);
console.error(fileContent.substring(start, end));
console.error('----------------------------------------------------');
}
}