ndjson 0.2.2 copy "ndjson: ^0.2.2" to clipboard
ndjson: ^0.2.2 copied to clipboard

Tiny and simple ndjson parser library for Dart. No external dependencies.

example/ndjson_example.dart

import 'dart:io';

import 'package:ndjson/ndjson.dart';

final File ndjsonValidSample = File('./data/object.ndjson');
Stream<List<int>> get ndjsonSource => ndjsonValidSample.openRead();

void main() async {
  await _usingFunction();
  await _usingExtension();
  await _usingExtensionWithConverter();
}

Future<void> _usingFunction() async {
  final Stream<NdjsonLine> ndjson = parseNdjson(byteStream: ndjsonSource);

  print(await ndjson.toList());
}

Future<void> _usingExtension() async {
  final Stream<NdjsonLine> ndjson = ndjsonSource.parseNdjson();

  print(await ndjson.toList());
}

Future<void> _usingExtensionWithConverter() async {
  final Stream<Dummy> ndjson = ndjsonSource.parseNdjsonWithConverter<Dummy>(
    whenMap: Dummy.fromJson,
  );

  print(await ndjson.toList());
}

class Dummy {
  const Dummy(this.id, this.name);

  factory Dummy.fromJson(Map<String, dynamic> map) {
    return Dummy(map['id'] as int, map['name'] as String);
  }

  final int id;
  final String name;
}
1
likes
160
pub points
5%
popularity

Publisher

verified publisheralexrintt.io

Tiny and simple ndjson parser library for Dart. No external dependencies.

Repository (GitHub)
View/report issues

Documentation

Documentation
API reference

Funding

Consider supporting this project:

donate.alexrintt.io
github.com

License

MIT (license)

More

Packages that depend on ndjson