Skip to content
Convert ndjson to json without JSON parsing.
TypeScript JavaScript HCL
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github
src
test
.gitignore
.travis.yml
LICENSE
README.md
package.json
tsconfig.json
yarn.lock initial commit Feb 28, 2019

README.md

ndjson-to-json-text Build Status

Convert ndjson text to JSON text without JSON parsing.

This library convert ndjson ndjson 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

You can’t perform that action at this time.