An open API service indexing awesome lists of open source software.

https://github.com/alexcmgit/ndjson.dart

Tiny and small library for parsing ndjson.
https://github.com/alexcmgit/ndjson.dart

dart dev ndjson parser pub stream

Last synced: 24 days ago
JSON representation

Tiny and small library for parsing ndjson.

Awesome Lists containing this project

README

        

# ndjson parser for Dart

[![Pub Version](https://img.shields.io/pub/v/ndjson)](https://pub.dev/packages/ndjson) [![Pub Version](https://img.shields.io/pub/points/ndjson)](https://pub.dev/packages/ndjson)

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

## Installation

```yaml
dependencies:
ndjson: ^
```

Import:

```dart
import 'package:ndjson/ndjson.dart';
```

## Usage

The usage is pretty straightforward:

```dart
import 'package:ndjson/ndjson.dart';

// Your ndjson stream.
final Stream> ndjsonStream = ...

// A new stream that will parse all chunks and emit events
// for each new json object (not ndjson chunks).
final Stream parsedNdjson = ndjsonStream.parseNdjson();

// Using converter functions:
final Stream ndjson = ndjsonSource.parseNdjsonWithConverter(
whenMap: Dummy.fromJson,
);
```

---

Supported ndjson types are:

- `Stream>`.
- `Stream`.
- `Stream`.

---

Any list-like ndjson source can be converted to `Stream` using:

```dart
Stream.fromIterable(ndjsonList);
```

**You must be aware that using ndjson as list is the same as a regular json (you lose all ndjson performance benefits).**