npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jsonlines-loader

v1.1.1

Published

JSON lines (jsonl) loader module for webpack

Downloads

45

Readme

npm node deps cover chat size

jsonlines-loader

A webpack loader for parsing JSON Lines files into JavaScript objects.

JSON Lines files consist of zero to many 'lines' separated by linebreak characters '\n', with each line containing a valid JSON value. They are often used for log files or data output.

jsonlines-loader enables JSON Lines files, which usually have a ".jsonl" extension, to be imported directly into JavaScript. The contents of the file is delivered as an array of JavaScript objects, each corresponding to one line of the JSON Lines file. Note that the array starts at index 1, which is line 1 of the file; index 0 in the array is empty.

Getting Started

To begin, you'll need to install jsonlines-loader:

$ npm install jsonlines-loader --save-dev

You can use the loader either:

  • by configuring the jsonlines-loader in the module.rules object of the webpack configuration, or
  • by directly using the jsonlines-loader! prefix to the require statement.

Suppose we have the following jsonl file:

file.jsonl

// file.jsonl
{"source":"A","errors":13}
{"source":"B","errors":4}
{"source":"C","errors":984,"status":"critical"}

Usage with preconfigured rule

webpack.config.js

// webpack.config.js
module.exports = {
  entry: "./index.js",
  output: {
    /* ... */
  },
  module: {
    rules: [
      {
        // make all files ending in .jsonl use the `jsonlines-loader`
        test: /\.jsonl$/,
        use: "jsonlines-loader",
        type: "javascript/auto"
      }
    ]
  }
};
// index.js
var data = require("./file.jsonl");
// or, in ES6
// import data from './file.jsonl'

console.log(data[1].errors); // 13

Usage with require statement loader prefix

var data = require("jsonlines-loader!./file.jsonl");

console.log(data[2].errors); // 4

Options

ignoreParseErrors

Ordinarily the Webpack build will fail if any of the lines of the JSON Lines file does not contain a valid JSON value. If you set ignoreParseErrors: true then any line that does not contain a valid JSON value will simply be copied into the delivered array as a string.

// webpack.config.js
module: {
  rules: [
    {
      // make all files ending in .jsonl use the `jsonlines-loader`
      test: /\.jsonl$/,
      use: [
        (loader: "jsonlines-loader"),
        (options: { ignoreParseErrors: true })
      ],
      type: "javascript/auto"
    }
  ];
}

License

MIT