parseFile static method

dynamic parseFile(
  1. String filePath
)

Reads a JSON file and returns a Map or List

Implementation

static dynamic parseFile(String filePath) {
  final file = File(filePath);

  if (!file.existsSync()) {
    throw Exception('JSON file not found: $filePath');
  }

  try {
    final content = file.readAsStringSync();
    return jsonDecode(content);
  } on FormatException catch (e) {
    throw Exception('Invalid JSON format: ${e.message}');
  } catch (e) {
    throw Exception('Failed to read JSON: $e');
  }
}