UNPKG

json-nd

Version:

json-nd is a module that provides functions to parse and stringify newline-delimited JSON (NDJSON) data.

11 lines (9 loc) 274 B
export class NdJson { static parse<T>(data: string): T[] { const lines = data.trim().split('\n'); return lines.map(line => JSON.parse(line)) as T[]; } static stringify(data: any[]): string { return data.map(item => JSON.stringify(item)).join('\n'); } }