Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

json-nd

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-nd

json-nd is a module that provides functions to parse and stringify newline-delimited JSON (NDJSON) data.

latest
Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
23K
-67.1%
Maintainers
1
Weekly downloads
 
Created
Source

json-nd

NdJson is a utility class for parsing and stringifying newline-delimited JSON (NDJSON) data.

Installation

npm install json-nd

Usage

Parsing NDJSON

import { NdJson } from 'json-nd';

const data = `
{"name":"John","age":30}
{"name":"Jane","age":25}
{"name":"Bob","age":40}
`;

const parsedData = NdJson.parse<{ name: string, age: number }>(data);
console.log(parsedData);
// Output: [{ name: 'John', age: 30 }, { name: 'Jane', age: 25 }, { name: 'Bob', age: 40 }]

Stringifying to NDJSON

import { NdJson } from 'json-nd';

const jsonData = [
  { name: 'John', age: 30 },
  { name: 'Jane', age: 25 },
  { name: 'Bob', age: 40 }
];

const ndjsonData = NdJson.stringify(jsonData);
console.log(ndjsonData);
// Output:
// {"name":"John","age":30}
// {"name":"Jane","age":25}
// {"name":"Bob","age":40}

API

NdJson.parse<T>(data: string): T[]

Parses NDJSON data into an array of objects of type T.

  • data: The NDJSON data to parse.
  • Returns: An array of objects of type T parsed from the NDJSON data.

NdJson.stringify(data: any[]): string

Converts an array of objects into NDJSON format.

  • data: The array of objects to stringify.
  • Returns: The NDJSON string representation of the input data.

License

This project is licensed under the BSD-3-Clause.

Keywords

ndjson

FAQs

Package last updated on 15 Jun 2023

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