json-split-transformer
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

json-split-transformer

A fast and lightweight transformer to transform chunks of JSON strings to valid JSON strings

GitHub license npm version build Dependabot semantic-release

Usage

import { ArrayIterator } from 'asynciterator'
import JSONSplitTransformer from 'json-split-transformer';

const streamSplitter = new JSONSplitTransformer();

const iterator = new ArrayIterator<string>([
  "{\"time\":1625581",
  "199",
  "479,\"values\":[32,23]}{\"ti",
  "me\":1625581199482,\"values\":[31,12]}"
]);

// New iterator that will emit the objects
// {time: 1625581199479, values: [32, 23]}
// and
// {time: 1625581199482, values: [31, 12]}
const newIterator = iterator
  .map(buffer => buffer.toString())
  // Split up concatenated JSON strings
  .transform<string>({ transform: streamSplitter.transform })
  // Parse each JSON string
  .map(JSON.parse)

License

©2021–present Jesse Wright, MIT License.

Package Sidebar

Install

npm i json-split-transformer

Weekly Downloads

1

Version

1.0.3

License

MIT

Unpacked Size

7.36 kB

Total Files

5

Last publish

Collaborators

  • jeswr