Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
@discoveryjs/json-ext
Advanced tools
The @discoveryjs/json-ext npm package provides utilities for working with JSON data, including features for streaming, parsing, and stringifying large JSON objects and arrays. It is designed to handle JSON data efficiently, making it easier to work with large JSON files or streams of JSON data.
Streaming JSON parse
This feature allows for parsing newline-delimited JSON (NDJSON) from a stream, enabling efficient processing of large JSON files without loading them entirely into memory.
const { createReadStream } = require('fs');
const { parseNDJSON } = require('@discoveryjs/json-ext');
const stream = createReadStream('path/to/your/file.ndjson');
parseNDJSON(stream, (obj) => {
console.log(obj);
});
Stringify JSON to stream
This feature allows for stringifying JSON objects and piping them to a writable stream, which is useful for creating NDJSON files or streaming JSON data over the network.
const { createWriteStream } = require('fs');
const { stringifyStream } = require('@discoveryjs/json-ext');
const stream = createWriteStream('path/to/your/output.ndjson');
const objects = [{ foo: 'bar' }, { baz: 'qux' }];
stringifyStream(objects).pipe(stream);
JSONStream offers similar streaming JSON parsing and stringifying capabilities. It allows for parsing JSON files or streams using JSONPath-like expressions. Compared to @discoveryjs/json-ext, JSONStream focuses more on the streaming aspect and might be more suitable for scenarios where JSONPath expressions are needed for selecting data.
stream-json provides a toolkit for processing JSON as a stream. It includes a variety of stream components for parsing, filtering, and transforming JSON data. While it shares the streaming JSON processing capability with @discoveryjs/json-ext, stream-json offers a more modular approach, allowing users to build custom processing pipelines.
A set of utilities that extend the use of JSON. Designed to be fast and memory efficient
Features:
stringifyInfo()
– Get estimated size and other facts of JSON.stringify() without converting a value to stringstringifyStream()
– Stringify stream (Node.js)npm install @discoveryjs/json-ext
Works the same as JSON.stringify()
, but returns an instance of ReadableStream
instead of string.
Compare with other solutions (benchmark)
Departs from JSON.stringify():
null
when JSON.stringify()
returns undefined
(since streams may not emit undefined
)value
, replacer
and space
arguments are the same as for JSON.stringify()
.
Result is an object:
{
minLength: Number, // mininmal bytes when values is stringified
circular: [...], // list of circular references
duplicate: [...], // list of objects that occur more than once
async: [...] // list of async values, i.e. promises and streams
}
Type: Boolean
Default: false
Collect async values (promises and streams) or not.
Type: Boolean
Default: false
Stop collecting info for a value or not whenever circular reference is found. Setting option to true
allows to find all circular references.
The version of library, e.g. "0.3.1"
.
MIT
FAQs
A set of utilities that extend the use of JSON
The npm package @discoveryjs/json-ext receives a total of 11,249,474 weekly downloads. As such, @discoveryjs/json-ext popularity was classified as popular.
We found that @discoveryjs/json-ext demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.