Web stream based jsonlines decoder/encoder

Overview

jsonlines-web

deno module deno doc npm version ci codecov GitHub Sponsors

Web stream based jsonlines decoder/encoder

  • Deno
  • browser
  • Node.js

This library supports JSON in the following formats:

  • Line-delimited JSON (JSONLinesParseStream)
    • NDJSON
    • JSON lines
  • Record separator-delimited JSON (JSONLinesParseStream)
  • Concatenated JSON (ConcatenatedJSONParseStream)

See wikipedia for the specifications of each JSON.

install or import

Deno

https://deno.land/x/jsonlines/ https://doc.deno.land/https://deno.land/x/jsonlines/mod.ts

import {
  ConcatenatedJSONParseStream,
  ConcatenatedJSONStringifyStream,
  JSONLinesParseStream,
  JSONLinesStringifyStream,
} from "https://deno.land/x/[email protected]/mod.ts";

browser

import {
  ConcatenatedJSONParseStream,
  ConcatenatedJSONStringifyStream,
  JSONLinesParseStream,
  JSONLinesStringifyStream,
} from "https://deno.land/x/[email protected]/js/mod.js";

Node.js

https://www.npmjs.com/package/jsonlines-web

npm install jsonlines-web
import {
  ConcatenatedJSONParseStream,
  ConcatenatedJSONStringifyStream,
  JSONLinesParseStream,
  JSONLinesStringifyStream,
} from "jsonlines-web";
// if you need
// import { TextDecoderStream, TextEncoderStream } from "node:stream/web";
// import { fetch } from "undici";

Usage

A working example can be found at ./testdata/test.ts.

How to parse JSON Lines

./json-lines.jsonl

{"some":"thing"}
{"foo":17,"bar":false,"quux":true}
{"may":{"include":"nested","objects":["and","arrays"]}}
import { JSONLinesParseStream } from "https://deno.land/x/[email protected]/mod.ts";

const { body } = await fetch(
  "https://deno.land/x/[email protected]/testdata/json-lines.jsonl",
);

const readable = body!
  .pipeThrough(new TextDecoderStream())
  .pipeThrough(new JSONLinesParseStream());

for await (const data of readable) {
  console.log(data);
}

How to parse json-seq

./json-seq.json-seq

�{"some":"thing\n"}
�{
  "may": {
    "include": "nested",
    "objects": [
      "and",
      "arrays"
    ]
  }
}
import { JSONLinesParseStream } from "https://deno.land/x/[email protected]/mod.ts";

const { body } = await fetch(
  "https://deno.land/x/[email protected]/testdata/json-seq.json-seq",
);

const recordSeparator = "\x1E";
const readable = body!
  .pipeThrough(new TextDecoderStream())
  .pipeThrough(new JSONLinesParseStream({ separator: recordSeparator }));

for await (const data of readable) {
  console.log(data);
}

How to parse concat-json

./concat-json.concat-json

{"foo":"bar"}{"qux":"corge"}{"baz":{"waldo":"thud"}}
import { ConcatenatedJSONParseStream } from "https://deno.land/x/[email protected]/mod.ts";

const { body } = await fetch(
  "https://deno.land/x/[email protected]/testdata/concat-json.concat-json",
);

const readable = body!
  .pipeThrough(new TextDecoderStream())
  .pipeThrough(new ConcatenatedJSONParseStream());

for await (const data of readable) {
  console.log(data);
}

How to stringify JSON Lines

import { readableStreamFromIterable } from "https://deno.land/[email protected]/streams/mod.ts";
import { JSONLinesStringifyStream } from "https://deno.land/x/[email protected]/mod.ts";

const file = await Deno.open(new URL("./tmp.concat-json", import.meta.url), {
  create: true,
  write: true,
});

readableStreamFromIterable([{ foo: "bar" }, { baz: 100 }])
  .pipeThrough(new JSONLinesStringifyStream())
  .pipeThrough(new TextEncoderStream())
  .pipeTo(file.writable)
  .then(() => console.log("write success"));

How to stringify json-seq

import { readableStreamFromIterable } from "https://deno.land/[email protected]/streams/mod.ts";
import { JSONLinesStringifyStream } from "https://deno.land/x/[email protected]/mod.ts";

const recordSeparator = "\x1E";
const file = await Deno.open(new URL("./tmp.concat-json", import.meta.url), {
  create: true,
  write: true,
});

readableStreamFromIterable([{ foo: "bar" }, { baz: 100 }])
  .pipeThrough(new JSONLinesStringifyStream({ separator: recordSeparator }))
  .pipeThrough(new TextEncoderStream())
  .pipeTo(file.writable)
  .then(() => console.log("write success"));

How to stringify concat-json

import { readableStreamFromIterable } from "https://deno.land/[email protected]/streams/mod.ts";
import { ConcatenatedJSONStringifyStream } from "https://deno.land/x/[email protected]/mod.ts";

const file = await Deno.open(new URL("./tmp.concat-json", import.meta.url), {
  create: true,
  write: true,
});

readableStreamFromIterable([{ foo: "bar" }, { baz: 100 }])
  .pipeThrough(new ConcatenatedJSONStringifyStream())
  .pipeThrough(new TextEncoderStream())
  .pipeTo(file.writable)
  .then(() => console.log("write success"));

note

This library contains ReadableStream.prototype[Symbol.asyncIterator] polyfills. Importing this library will automatically enable ReadableStream.prototype[Symbol.asyncIterator].

develop

need to manually deno task transpile before release.

You might also like...

An ultra-high performance stream reader for browser and Node.js

QuickReader An ultra-high performance stream reader for browser and Node.js, easy-to-use, zero dependency. Install npm i quickreader Demo import {Quic

Nov 28, 2022

The best tool to make your stream prettier.

Streali The best tool to make your stream prettier. Streali provides you with tools to make your streaming experience easier. Whether to display alert

Sep 19, 2022

Open Source Memedows Stream Control.

Open Source Memedows Stream Control.

The dumbest way to control OBS with JavaScript memedows is a project built for my Twitch Stream. To run a bunch of interactive and automated elements

Aug 20, 2022

A bullet journaling plugin for Obsidian that aggregates a terse stream of backlinked clippings in the footer of notes.

A bullet journaling plugin for Obsidian that aggregates a terse stream of backlinked clippings in the footer of notes.

A plugin for Obsidian that aggregates a terse stream of backlinked clippings in the footer of notes. Intended usage pattern: (Or: How to get the most

Jan 4, 2023

The best tool to make your stream prettier.

The best tool to make your stream prettier.

The best tool to make your stream prettier. Streali provides you with tools to make your streaming experience easier. Whether to display alerts or hig

Sep 21, 2022

🎭 EmoteOnly mode on stream end.

Emote only bot What is this? Trolls are everywhere. They can try to get your channel banned at any moment. To counter this, we can enable emote mode w

Oct 3, 2022

MQTT broker that can run on any stream server

 MQTT broker that can run on any stream server

Nest.js MQTT broker that can run on any stream server Topics What is MQTT ? Installation Usage Handlers Events Methods Packets Middleware & Plugins De

Nov 26, 2022

375 DSA Tracker helps you build your confidence in solving any coding related question and helps you prepare for your placements. It is your personal web-based progress tracker based on 375 DSA Sheet by Aman Dhattarwal & Shradha Didi

375 DSA Tracker helps you build your confidence in solving any coding related question and helps you prepare for your placements. It is your personal web-based progress tracker based on 375 DSA Sheet by Aman Dhattarwal & Shradha Didi

375-DSA Tracker 👨‍💻 Me and my friend Abhilash Jena made a 375 DSA Tracker website based on 375 DSA Sheet by Aman Dhattarwal & Shradha Didi which hel

Nov 11, 2022

The Taste food web app is our JavaScript capstone project, Taste food is a web application based on an external food API, showing data about Italian foods and we used Used involvement API to record the different user interactions (likes, comments).

taste-food The Taste food web app is our JavaScript capstone project, Taste food is a web application based on an external food API TheMealDB, showing

Aug 10, 2022
Comments
Releases(v1.2.1)
Owner
ayame113
College student
ayame113
base64 decoder and encoder for nextjs 🎉

next-base64 next-base64 is a library for client-side and server-side base64 encoding and decoding Installation # Using npm npm install --save next-bas

Yony Calsin 5 Sep 11, 2022
z-base-32 encoder & decoder

z32 z-base-32 encoder & decoder npm install z32 Usage const z32 = require('z32') const s = z32.encode('Hello, World!') console.log(s) // jb1sa5dxfo

Mathias Buus 7 Jun 19, 2022
TypeScript dotbim parser and encoder.

dotbim-ts Open-source TypeScript parser and encoder for dotbim file format. dotbim's website: https://dotbim.net/ Here you can find small manual for d

Baid 5 Aug 2, 2022
🔆🔎👀 Smart Contract Storage Viewer, DataType Guesser, Toolbox & Transaction Decoder

?? ?? ?? Smart Contract Storage HexViewer Demo Target - the target contract API Endpoint - your infura (or equivalent) api key Retrieves smart contrac

tintin 85 Nov 27, 2022
It shows an effective way to correct bus arrival information using data analytics based on Amazon Serverless such as Kiness Data Stream, Kinesis Data Firehose, S3, and Lambda.

Amazon Serverless를 이용한 실시간 버스 정보 수집 및 저장 본 github repository는 버스 정보를 주기적으로 수집하여 분석할 수 있도록, Amazon Serverless인 Amazon Kinesis Data Stream, Kinesis Data

John Park 4 Nov 13, 2022
A web applicaton called 'MOVTIME' where you can come to stream movies by consuming the TMDB movie API

End result Click here : https://movtime-movie-app.netlify.app/ Figma design File Click here: https://www.figma.com/file/4IbpmTU6jtpRKdpbFmt4i8/Web-Des

Eniola Odunmbaku 12 Nov 11, 2022
This repo is a collection of code samples and links to previous twitch live stream sessions. If you have any ideas or suggestions for future episodes, feel free to open an issue.

Talk DEV to me Talk DEV to me is a monthly show on twitch.tv/aws hosted by Tiago Barbosa and Alex Melnyk, where we invite customers, partners, or Amaz

AWS Samples 122 Jan 6, 2023
Stream Chat Messaging Example App

Stream Chat Messaging Example App Is your core product something that would benefit from the increased engagement that comes from in-app chat? With St

Ashutosh Mohanty 7 Nov 20, 2022
A CLI to stream movies, TV shows etc. from your terminal, for free.

Streaminal A CLI to stream movies, TV shows etc. from your terminal, for free. Installation Install streaminal globally with npm npm install -g stream

null 13 Aug 30, 2022
Demo for my talk "Stream Away the Wait" – a talk about making excellent pending experiences.

?? Stream Away the Wait When implementing the design of a user interface, we often finish before remembering that not everyone's running the app's ser

Kent C. Dodds 25 Nov 1, 2022