🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

ldjson-stream

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ldjson-stream

streaming line delimited json parser + serializer

0.0.1
Source
npm
Version published
Weekly downloads
322K
16.01%
Maintainers
1
Weekly downloads
 
Created

What is ldjson-stream?

The ldjson-stream npm package is designed to handle line-delimited JSON (LDJSON) streams. It provides utilities for parsing and stringifying LDJSON data, which is useful for processing large datasets in a memory-efficient manner.

What are ldjson-stream's main functionalities?

Parsing LDJSON

This feature allows you to parse a stream of line-delimited JSON data. The code sample reads from a file named 'data.ldjson' and parses each line as a JSON object, logging each object to the console.

const ldjson = require('ldjson-stream');
const fs = require('fs');

fs.createReadStream('data.ldjson')
  .pipe(ldjson.parse())
  .on('data', obj => {
    console.log(obj);
  });

Stringifying LDJSON

This feature allows you to stringify a stream of JSON objects into line-delimited JSON format. The code sample takes an array of objects and writes them to a file named 'output.ldjson' in LDJSON format.

const ldjson = require('ldjson-stream');
const fs = require('fs');

const data = [
  { name: 'Alice', age: 30 },
  { name: 'Bob', age: 25 }
];

const writeStream = fs.createWriteStream('output.ldjson');
const stringifyStream = ldjson.serialize();

stringifyStream.pipe(writeStream);
data.forEach(item => stringifyStream.write(item));
stringifyStream.end();

Other packages similar to ldjson-stream

FAQs

Package last updated on 30 Aug 2013

Did you know?

Socket

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.

Install

Related posts