You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

ndjson

Package Overview
Dependencies
Maintainers
3
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ndjson

Streaming newline delimited json parser + serializer

2.0.0
latest
Source
npm
Version published
Maintainers
3
Created

What is ndjson?

The ndjson npm package is used for parsing and stringifying newline-delimited JSON (NDJSON) data. NDJSON is a convenient format for streaming JSON data, where each line is a valid JSON object. This package allows you to easily work with NDJSON data in Node.js applications.

What are ndjson's main functionalities?

Parsing NDJSON

This feature allows you to parse NDJSON data from a readable stream. The code sample reads NDJSON data from a file and parses each line into a JSON object, which is then logged to the console.

const ndjson = require('ndjson');
const fs = require('fs');

fs.createReadStream('data.ndjson')
  .pipe(ndjson.parse())
  .on('data', function(obj) {
    console.log('Parsed object:', obj);
  });

Stringifying NDJSON

This feature allows you to stringify JSON objects into NDJSON format. The code sample takes an array of JSON objects and writes them to a file in NDJSON format.

const ndjson = require('ndjson');
const fs = require('fs');

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

const stringifyStream = ndjson.stringify();
stringifyStream.pipe(fs.createWriteStream('output.ndjson'));
data.forEach(item => stringifyStream.write(item));
stringifyStream.end();

Other packages similar to ndjson

Keywords

ndjson

FAQs

Package last updated on 15 Aug 2020

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