https://github.com/ivangabriele/from-ndjson
Convert ndjson stringified data into JSON-object arrays.
https://github.com/ivangabriele/from-ndjson
convert json ndjson parse parser
Last synced: about 2 months ago
JSON representation
Convert ndjson stringified data into JSON-object arrays.
- Host: GitHub
- URL: https://github.com/ivangabriele/from-ndjson
- Owner: ivangabriele
- License: mit
- Created: 2021-08-29T11:50:22.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-06-06T21:53:45.000Z (11 months ago)
- Last Synced: 2025-02-27T04:11:28.503Z (2 months ago)
- Topics: convert, json, ndjson, parse, parser
- Language: JavaScript
- Homepage:
- Size: 725 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# from-ndjson
[![License][img-license]][lnk-license]
[![CI Status][img-github]][lnk-github]
[![Code Coverage][img-codecov]][lnk-codecov]
[![NPM Version][img-npm]][lnk-npm]Convert ndjson stringified data into JSON-object arrays.
## Install
```sh
npm i -E from-ndjson
```or:
```sh
yarn add -E from-ndjson
```## Usage
```js
import fromNdjson from 'from-ndjson'const ndjsonSample = `
{ "some": "thing" }
{ "foo": 17, "bar": false, "quux": true }
{ "may": { "include": "nested", "objects" : ["and", "arrays"] } }
`const resultArray = fromNdjson(ndjsonSample)
console.log(resultArray[0])
// Output: { some: 'thing' }
console.log(resultArray[1])
// Output: { foo: 17, bar: false, quux: true }
```## API
### fromNdjson(input, options?)
```ts
function fromNdjson(data: string, options: FromNdjson.Options)
```#### Options
##### isStrict
Type: `boolean`\
Default: `'false'`By default, `fromNdjson()` will just skip the rows that `JSON.parse()` can't parse. If you have an ndjson with 5 rows
and 2 unparsable ones, the returned array will only contain 3 rows: the ones that could be parsed.You can specify `{ isStrict: true }` if you prefer an error to be thrown when a row is invalid.
## Contribute
Please check the [CONTRIBUTING](CONTRIBUTING.md) document.
---
[img-codecov]: https://img.shields.io/codecov/c/github/ivangabriele/from-ndjson/main?style=flat-square
[img-github]: https://img.shields.io/github/workflow/status/ivangabriele/from-ndjson/Check/main?style=flat-square
[img-license]: https://img.shields.io/github/license/ivangabriele/from-ndjson?style=flat-square
[img-npm]: https://img.shields.io/npm/v/from-ndjson?style=flat-square
[lnk-codecov]: https://app.codecov.io/gh/ivangabriele/from-ndjson/branch/main
[lnk-github]: https://github.com/ivangabriele/from-ndjson/actions?query=branch%3Amain++
[lnk-license]: https://github.com/ivangabriele/from-ndjson/blob/main/LICENSE
[lnk-npm]: https://www.npmjs.com/package/from-ndjson