Skip to content

code4fukui/JSONL

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSONL

JSONL is a JSON Lines library, stringify / parse / streaming read and write as JavaScript ES modules for browsers and Deno.

usage

stringify & parse

import { JSONL } from "https://code4fukui.github.io/JSONL/JSONL.js";

const data = [
  { a: 1, b: "abc" },
  { a: 2, b: "def" },
];
const s = JSONL.stringify(data);
console.log(s);
const data2 = JSONL.parse(s);
console.log(data2);

stream write

import { JSONLWriter } from "https://code4fukui.github.io/JSONL/JSONLWriter.js";

const w = new JSONLWriter("test.jsonl");
await w.writeRecord({ name: "abc", value: 123 });
await w.writeRecord({ name: "def", value: 456 });
w.close();

stream read

import { JSONLReader } from "https://code4fukui.github.io/JSONL/JSONLReader.js";

const r = new JSONLReader("test.jsonl");
for (;;) {
  const data = await r.readRecord();
  if (data == null) {
    break;
  }
  console.log(data);
}
r.close();

reference

see also

About

JSON Lines stringify / parse in JavaScript ES module for browsers and Deno

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%