json-event-parser
TypeScript icon, indicating that this package has built-in type declarations

1.0.0-beta.1 • Public • Published

JSON Event Parser

Build status npm version

A streaming SAX-style JSON parser.

This is a fork of jsonparse.

Installation

$ npm install json-event-parser

or

$ yarn add json-event-parser

This package also works out-of-the-box in browsers via tools such as webpack and browserify.

Usage

Example:

import {JsonEventParser} from 'json-event-parser';
import {Readable} from "stream";

Readable.from(['{"test": "fo', 'o"}'])
    .pipe(new JsonEventParser())
    .on("end", () => console.log('Parsing done!'))
    .on("error" => error => console.error(error))
    .on("data", event => console.log(`Event of type ${event.type}`));

The event fields are:

  • type: the event type. Might be "value" (a plain value i.e. a string, a number, a boolean or null), "open-array" and "close-array" to mark that an array is opened and close, or "open-object" and "close-object" to mark the same thing with objects.
  • value: used on the "value" type to store the value itself.
  • key: used on the "value", "open-array" and "open-object" to store the key in the parent object or the position in the parent array.

License

This code is released under the MIT license.

Readme

Keywords

none

Package Sidebar

Install

npm i json-event-parser

Weekly Downloads

0

Version

1.0.0-beta.1

License

MIT

Unpacked Size

29.2 kB

Total Files

7

Last publish

Collaborators

  • rubensworks