Socket
Socket
Sign inDemoInstall

jsonlines

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsonlines

Parse [JSONLines](http://jsonlines.org) with Node.js.


Version published
Maintainers
1
Created

What is jsonlines?

The jsonlines npm package is used for reading and writing JSON Lines, a format for storing structured data that is easy to process one record at a time. Each line in a JSON Lines file is a valid JSON value, separated by newline characters.

What are jsonlines's main functionalities?

Reading JSON Lines

This code demonstrates how to read a JSON Lines file using the jsonlines package. It creates a readable stream from an input file and pipes it to the jsonlines parser. The parser emits 'data' events for each parsed JSON object.

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

const input = fs.createReadStream('input.jsonl');
const reader = jsonlines.parse();

input.pipe(reader);

reader.on('data', (obj) => {
  console.log('Parsed object:', obj);
});

reader.on('end', () => {
  console.log('Finished reading file.');
});

Writing JSON Lines

This code demonstrates how to write JSON objects to a JSON Lines file using the jsonlines package. It creates a writable stream to an output file and pipes it to the jsonlines stringifier. JSON objects are written to the stringifier, which then writes them to the file.

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

const output = fs.createWriteStream('output.jsonl');
const writer = jsonlines.stringify();

writer.pipe(output);

writer.write({ foo: 'bar' });
writer.write({ baz: 'qux' });
writer.end();

Other packages similar to jsonlines

FAQs

Package last updated on 14 Jun 2017

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc