ndjson-to-json-text
v1.0.2
Published
Convert ndjson to json text without JSON parsing.
Downloads
3,150
Readme
ndjson-to-json-text
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
- You should
- 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
- madnight/ndjson-to-json: Converts NDJSON to JSON
- It only work on Node.js
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.
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
Author
License
MIT © azu