You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Drop support for node 0.10 because streams are broken.
Fix transform streams for node 0.12
* Make cycling off by default.
* Emit errors from Promises and Streams.
Add path property.
* Complete rewrite.
var JsonStreamStringify =require('JsonStreamStringify/umd.polyfill');
25
65
```
26
66
67
+
**Note:** This library is primarily written for LTS versions of NodeJS. Other environments are not tested.
68
+
**Note on non-NodeJS usage:** This module depends on node streams library. Any Streams3 compatible implementation should work - as long as it exports a Readable class, with instances that looks like readable streams.
69
+
**Note on Polyfills:** I have taken measures to minify global pollution of polyfills but this library **does not load polyfills by default** because the polyfills modify native object prototypes and it goes against the [W3C recommendations](https://www.w3.org/2001/tag/doc/polyfills/#advice-for-library-and-framework-authors).
Convert value to JSON string. Returns a readable stream.
31
-
-``value`` Any data to convert to JSON.
32
-
-``replacer`` Optional ``Function(key, value)`` or ``Array``.
33
-
As a function the returned value replaces the value associated with the key. [Details](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_replacer_parameter)
-``replacer`` Optional ``Function(key, value)`` or ``Array``
82
+
As a function the returned value replaces the value associated with the key. [Details](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_replacer_parameter)
34
83
As an array all other keys are filtered. [Details](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Example_with_an_array)
35
-
-``spaces`` Optional ``String`` or ``Number``**Not yet implemented**
36
-
-``noDecycle`` Optional ``Boolean`` Set to ``true`` to disable decycling.
84
+
85
+
-``spaces`` Optional ``String`` or ``Number``
86
+
A String or Number object that's used to insert white space into the output JSON string for readability purposes. If this is a Number, it indicates the number of space characters to use as white space. If this is a String, the string is used as white space. If this parameter is not recognized as a finite number or valid string, no white space is used.
87
+
88
+
-``cycle`` Optional ``Boolean``
89
+
``true`` enables cycling of cyclical structures and dags.
90
+
To restore cyclical structures; use [Crockfords Retrocycle method](https://github.com/douglascrockford/JSON-js) on the parsed object (not included in this module).
91
+
92
+
**Returns**
93
+
-``JsonStreamStringify`` object that exposes a [Streams3 interface](https://nodejs.org/api/stream.html#stream_class_stream_readable).
94
+
95
+
### jsonStreamStringify#path
96
+
97
+
**Returns**
98
+
-``Array[String, Number]``
99
+
Current path being serialized as an array of Strings (keys of objects) and Numbers (index into arrays).
100
+
Can be transformed into an mpath with ``.join('.')``.
101
+
Useful in conjunction with ``.on('error', ...)``, for figuring out what path may have caused the error.
Uses toJSON when available, and JSON.stringify to stringify everything but objects and arrays.
101
-
Streams with ObjectMode=true are output as arrays while ObjectMode=false output as a concatinated string (each chunk is piped with transforms).
102
-
103
-
Circular structures are handled using a WeakMap based implementation of [Douglas Crockfords Decycle method](https://github.com/douglascrockford/JSON-js/blob/master/cycle.js). To restore circular structures; use Crockfords Retrocycle method on the parsed object.
0 commit comments