ndjson-to-json-text
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

ndjson-to-json-text Build Status

Convert ndjson text to JSON text without JSON parsing.

This library convert ndjson text to json text.

{"id":1,"name":"Alice"}
{"id":2,"name":"Bob"}
{"id":3,"name":"Carol"}

to

[{"id":1,"name":"Alice"},{"id":2,"name":"Bob"},{"id":3,"name":"Carol"}]

Purpose

  • Just convert ndjson(text file) to json(text file)
    • You should JSON.parse the result json text outside of this library
  • No use JSON.parse in this library
    • It is a cost

Install

Install with npm:

npm install ndjson-to-json-text

Usage

/**
 * Convert ndjson text to JSON text
 * The return value is a string of JSON array text
 * @param ndjsonText
 */
export declare function ndjsonToJsonText(ndjsonText: string): string;

Example

const jsonText = ndjsonToJsonText(
`{"id":1,"name":"Alice"}
{"id":2,"name":"Bob"}
{"id":3,"name":"Carol"}`)
console.log(jsonText);
// [{"id":1,"name":"Alice"},{"id":2,"name":"Bob"},{"id":3,"name":"Carol"}]
const json = JSON.parse(jsonText);
// actual json object!!

Related

Changelog

See Releases page.

Running tests

Install devDependencies and Run npm test:

npm test
# Update snapshot
npm run updateSnapshot

Contributing

Pull requests and stars are always welcome.

For bugs and feature requests, please create an issue.

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Author

License

MIT © azu

Readme

Keywords

Package Sidebar

Install

npm i ndjson-to-json-text

Weekly Downloads

1,145

Version

1.0.2

License

MIT

Unpacked Size

6.53 kB

Total Files

7

Last publish

Collaborators

  • azu