Highland Json

A JSON encoder for Highland.js stream
Alternatives To Highland Json
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
Rootencoder2,211
a day ago235apache-2.0Java
RootEncoder for Android (rtmp-rtsp-stream-client-java) is a stream encoder to push video/audio to media servers using protocols RTMP, RTSP and SRT with all code written in Java/Kotlin
Csv472200545 days ago46November 26, 20232mitElixir
CSV Decoding and Encoding for Elixir
Cocoasplit338
4 years ago30Objective-C
Stream/record your desktop/webcam to twitch/owned etc.
Streaming Json Encoder29465a year ago7December 09, 2022mitPHP
PHP library for iteratively encoding large JSON documents piece by piece
Switch Remote Play220
a year ago16gpl-3.0C++
Let the switch remotely play PC games (similar to steam link or remote play)
Mp4 Stream19714493 years ago13February 24, 202113mitJavaScript
Streaming mp4 encoder and decoder
Csv Write Stream1884421583 years ago12April 28, 201612bsd-2-clauseJavaScript
A CSV encoder stream that produces properly escaped CSVs
Decompress111
2 months ago7mitOCaml
Pure OCaml implementation of Zlib.
Audify96128 months ago38April 11, 202311mitC++
Play/Stream/Record PCM audio data & Encode/Decode Opus to PCM audio data
Jpg Stream7525106 years ago7August 23, 20173C++
A streaming JPEG encoder and decoder
Alternatives To Highland Json
Select To Compare


Alternative Project Comparisons
Readme

Highland-json

Greenkeeper badge JSON encoding for Highland.js stream.

Build Status

This JSON encoder not only encoding stream of objects, but also encode streams recursively. You can pass a stream of stream of number, and it will return an array of array of number.

Install

npm install highland-json

Usage

Encoding array of objects


import _ from 'highland';
import {stringify} from 'highland-json';

const input = [
	{ a : "b", b : "c" },
	{ a : [1, 2, 3] },
	[ 1, 2, 3 ],
	[ { a : "b", b : "c" } ]
];

_(input)
.through(stringify)
.toArray(results => {
	let result = results.join('');
	
	// result === input
});

Streams in array are recursively encoded


import _ from 'highland';
import {stringify} from 'highland-json';

const input = [
	{ a : "b", b : "c" },
	_([ 1, 2, 3 ]),
	_([ {
		a : "b",
		b : _([4, 5, 6])
		}
	])
];

_(input)
.through(stringify)
.toArray(results => {
	let result = results.join('');
	/*
	result === [
		{ "a" : "b", "b" : "c" },
		[ 1, 2, 3 ],
		[ {
			"a" : "b",
			"b" : [4, 5, 6]
		} ]
	];*/
});

Encoding object

stringifyObj accepts a stream of [key, value] array.


import _ from 'highland';
import {stringifyObj} from 'highland-json';

/* Key value pair */
const input = [
	['a', 'b'],
	['c', 'd'],
	['e', ['f', 'g', 'h']]
]

_(input)
.through(stringifyObj)
.toArray(results => {
	let result = results.join('');
	/*
	result === {
		"a": "b",
		"c": "d",
		"e": ["f", "g", "h"]
	} */
};

Encode existing object

stringifyObj also accepts stream of single object, the object will be encoded as an object ({}), please only pass one object to the stream. If the stream is given more than one object, it will output something like {"a":1}{"a":2}, which is not a valid JSON. Use stringifyfor that case.


import _ from 'highland';
import {stringifyObj} from 'highland-json';

/* Key value pair */
const input = {
	a: "b",
	c: "d",
	e: ["f", "g", "h"]
}

_(input)
.through(stringifyObj)
.toArray(results => {
	let result = results.join('');
	/*
	result === {
		"a": "b",
		"c": "d",
		"e": ["f", "g", "h"]
	} */
};

Nesting

Remember to pass through stringifyObj when you are encoding objects.

const input = {
	a : _([
			_([1, 2, 3]),
			_([4, 5, 6])
		]),
	b : _([{
			c: _([{
				d: 'e',
				f: 'g'
				}]).through(stringifyObj),
			h: _([{
				i: 'j',
				k: 'l'
				}]).through(stringifyObj)
			}
		]).through(stringifyObj)
};

_([input])
.through(stringifyObj)
.toArray(results => {
	let result = JSON.parse(results.join(''));
	/*
	result === {
		a : [[1,2,3], [4,5,6]],
		b : {
			c : {d:'e', f:'g'},
			h : {i:'j', k:'l'}
		}
	} */
});

Custom stringify

In case if you want to use a custom stringify function.

import _ from 'highland';
import {stringify} from 'highland-json';

const input = ['a', 'b', 'c'];
const customStringify = (val, stream)=> JSON.stringify(val + '1');

_(input)
.through(stringify({stringify: customStringify}))
.toArray(results => {
	let result = results.join('');
	// result === ['a1', 'b1', 'c1']
});
const input = {
	nums: _([1, 2, 3]),
	strings: _(['a', 'b', 'c']),
};

const customStringify = (val, stream)=> {
	if (stream === input.nums) {
		return JSON.stringify(val * 10);
	}
	if (stream === input.strings) {
		return JSON.stringify(val + '1');
	}
	throw new Error("Unreachable");
};

_([input])
.through(stringifyObj({stringify: customStringify}))
.toArray(results => {
	const result = JSON.parse(results.join(''));
	/*
	result === {
		nums: [10, 20, 30],
		strings: ['a1', 'b1', 'c1'],
	};
	*/
});
Popular Stream Projects
Popular Encoder Projects
Popular Control Flow Categories

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.
Javascript
Json
Stream
Encoding
Encoder
Stringify