1.0.3 • Published 3 years ago
json-split-transformer v1.0.3
json-split-transformer
A fast and lightweight transformer to transform chunks of JSON strings to valid JSON strings
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.