CSV to JSON and maps
Get CSV into the shape the rest of your program already speaks.
Install#
dart pub add csv_plusimport 'package:csv_plus/csv_plus.dart';Rows as maps#
final maps = CsvCodec().decodeToMaps('name,age\nAlice,30\nBob,25');
// [{name: Alice, age: 30}, {name: Bob, age: 25}]Straight to JSON#
import 'dart:convert';
import 'package:csv_plus/csv_plus.dart';
final maps = CsvCodec().decodeToMaps(csv);
final json = jsonEncode(maps);Because inference already produced real int and double values, the JSON contains numbers rather than quoted strings.
A two-column CSV as a map#
CsvCodec().decodeMap('host,localhost\nport,8080');
// {host: localhost, port: 8080}
CsvCodec().encodeMap({'host': 'localhost', 'port': 8080});Fusing with dart:convert#
final adapter = CsvCodec().asCodec(); // Codec<List<List<dynamic>>, String>
adapter.decode('a,b\n1,2');
final piped = adapter.fuse(utf8);