Convert ndjson to json without JSON parsing.
MIT License
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"}]
JSON.parse
the result json text outside of this libraryJSON.parse
in this library
Install with npm:
npm install ndjson-to-json-text
/**
* 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;
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!!
See Releases page.
Install devDependencies and Run npm test
:
npm test
# Update snapshot
npm run updateSnapshot
Pull requests and stars are always welcome.
For bugs and feature requests, please create an issue.
git checkout -b my-new-feature
git commit -am 'Add some feature'
git push origin my-new-feature
MIT azu