https://github.com/javascript-studio/studio-ndjson
☯️ Transforms to parse and stringify ndjson
https://github.com/javascript-studio/studio-ndjson
json ndjson parse stream stringify transform
Last synced: 16 days ago
JSON representation
☯️ Transforms to parse and stringify ndjson
- Host: GitHub
- URL: https://github.com/javascript-studio/studio-ndjson
- Owner: javascript-studio
- License: mit
- Created: 2017-05-30T16:46:51.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2024-01-11T10:35:34.000Z (over 1 year ago)
- Last Synced: 2025-03-27T15:51:53.807Z (about 1 month ago)
- Topics: json, ndjson, parse, stream, stringify, transform
- Language: JavaScript
- Size: 1 MB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- License: LICENSE
Awesome Lists containing this project
README
# Studio ndjson
☯️ Transforms to parse and stringify [ndjson][1].
> This module also works in the browser using a [naive `stream` shim][4] for
> small Browserify bundles.## Usage
To stringify an object stream into ndjson:
```js
const StringifyTransform = require('@studio/ndjson/stringify');object_stream.pipe(new StringifyTransform()).pipe(process.stdout);
```To parse ndjson into an object stream:
```js
const ParseTransform = require('@studio/ndjson/parse');process.stdin.pipe(new ParseTransform()).pipe(object_stream);
```## Install
```bash
❯ npm i @studio/ndjson
```## API
Require the transform you need:
- `@studio/ndjson/stringify`: Exports the `StringifyTransform` class which
reads objects and writes strings.
- `@studio/ndjson/parse`: Exports the `ParseTransform` class which reads
strings and writes objects.The module main exports `StringifyTransform` and `ParseTransform` if you need
both:```js
const { StringifyTransform, ParseTransform } = require('@studio/ndjson');
```### ParseTransform options
The `ParseTransform` constructor accepts an `options` object with these
properties:- `loose`: Whether to ignore data before the first `{` in each line.
- `loose_out`: A stream to receive data that was found before the first `{` in
each line. Implies `loose`.### Error handling
If `JSON.parse` or `JSON.stringify` throw an error, the transform emits an
`error` event with the error object having a `code` property with
`ERR_JSON_PARSE` or `ERR_JSON_STRINGIFY`. For parse errors, the `line` property
on the error is the string that could not be parsed.## Related modules
- 👻 [Studio Log][2]: This module was refactored out of the logger for
[JavaScript Studio][3].
- 💧 [Studio Browser Stream][4] is a naive `stream` shim for small Browserify
bundles.
- 📦 [Studio Changes][5] is used to create the changelog for this module.## License
MIT
Made with ❤️ on 🌍[1]: http://ndjson.org/
[2]: https://github.com/javascript-studio/studio-log
[3]: https://javascript.studio
[4]: https://github.com/javascript-studio/studio-browser-stream
[5]: https://github.com/javascript-studio/studio-changes