https://github.com/fabervitale/deno-ndjson
Read, write, parse and serialize new line delimited JSON in deno: http://ndjson.org/
https://github.com/fabervitale/deno-ndjson
deno ndjson parse typescript
Last synced: 25 days ago
JSON representation
Read, write, parse and serialize new line delimited JSON in deno: http://ndjson.org/
- Host: GitHub
- URL: https://github.com/fabervitale/deno-ndjson
- Owner: FaberVitale
- License: mit
- Created: 2020-05-17T08:47:55.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2022-05-21T11:32:35.000Z (almost 3 years ago)
- Last Synced: 2025-03-15T07:39:33.614Z (about 2 months ago)
- Topics: deno, ndjson, parse, typescript
- Language: TypeScript
- Homepage:
- Size: 39.1 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# deno-ndjson
## Decription
Read, write, parse and serialize newline delimited json, or
[ndjson](http://ndjson.org/) for short.## Usage
### parseNdjson
Parses the content of a
[Deno.Reader](https://doc.deno.land/https/github.com/denoland/deno/releases/latest/download/lib.deno.d.ts#Deno.Reader).Ignores parsing errors if options.strict is `false`.
```typescript
async function* parseNdjson(
reader: Deno.Reader,
options?: { strict: boolean },
): AsyncIterableIterator;
```#### example
```typescript
import { parseNdjson } from "https://deno.land/x/[email protected]/mod.ts";let file: Deno.File | null = null;
try {
file = await Deno.open("");for await (const parsed of parseNdjson(file)) {
console.log(parsed);
}
} catch (readError) {
// handle error
} finally {
file?.close();
}
```[source](./lib/parse.ts)
### readNdjson
Reads a Ndjson file and returns an array of parsed lines.
```typescript
async function readNdjson(filePath: string): Promise;
```#### example
```typescript
import { readNdjson } from "https://deno.land/x/[email protected]/mod.ts";const parsed = await readNdjson("");
```[source](./lib/read.ts)
### serializeNdJson
Serializes the content of an array.
```typescript
function serializeNdJson(data: unknown[]): string;
```#### example
```typescript
import { serializeNdJson } from "https://deno.land/x/[email protected]/mod.ts";const serialized: string = serializeNdJson([
{ who: "let" },
{ the: "dogs" },
{ out: "!" },
]);
```[source](./lib/serialize.ts)
### writeNdjson
Writes the content of an array to a file in ndjson format.
Optional third argument is
[Deno.WriteFileOptions](https://doc.deno.land/https/github.com/denoland/deno/releases/latest/download/lib.deno.d.ts#Deno.WriteFileOptions)
and is passed down to the writer.```typescript
async function writeNdjson(
filePath: string,
data: unknown[],
options?: Deno.WriteFileOptions,
): Promise;
```#### example
```typescript
import { writeNdjson } from "https://deno.land/x/[email protected]/mod.ts";const toBeWritten = [
{ message: "qui", level: "info", timestamp: "2020-05-08T14:05:25.091Z" },
{ message: "que", level: "info", timestamp: "2020-05-08T14:05:25.096Z" },
{ message: "quod", level: "info", timestamp: "2020-05-08T14:05:25.104Z" },
];await writeNdjson("", toBeWritten, { append: true });
```[source](./lib/write.ts)
---
## License
[MIT](./LICENSE)