-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-json.js
More file actions
37 lines (29 loc) · 1.13 KB
/
test-json.js
File metadata and controls
37 lines (29 loc) · 1.13 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
// Simple test script for checking JSON parsing
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
import fs from 'fs';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// Get the scorecard file path
const scorecardPath = join(__dirname, 'src/samples/sample-scorecard.json');
console.log(`Reading scorecard from: ${scorecardPath}`);
try {
// Read the file
const fileContent = fs.readFileSync(scorecardPath, 'utf8');
console.log('File content length:', fileContent.length);
console.log('First 100 characters:', fileContent.substring(0, 100));
// Parse JSON
const data = JSON.parse(fileContent);
// Print some stats
console.log('Scorecard parsed successfully');
console.log('Number of innings:', data.scorecard.length);
// Print first batsman's details
const firstBatsman = data.scorecard[0].batsman[0];
console.log('First batsman:', firstBatsman.name, 'scored', firstBatsman.runs, 'runs');
// Exit explicitly with success
process.exit(0);
} catch (error) {
console.error('Error:', error.message);
// Exit with failure code
process.exit(1);
}