Package Exports
- @discoveryjs/json-ext
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@discoveryjs/json-ext) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
json-ext
A set of utilities that extend the use of JSON.
Features:
- Value info:
info()
- Stringify stream:
stringifyStream()
- TBD Parse stream
- TBD Support for circular references
- TBD Binary representation
Install
npm install @discoveryjs/json-ext
API
stringifyStream(value[, replacer[, space]])
Works the same as JSON.stringify()
, but returns an instance of ReadableStream
instead of string.
Extensions:
- Output
null
to the output whenJSON.stringify()
returnsundefined
(since streams may not to emit undefined) - A promise is resolving and the result value is stringifying as a regular value
- A Stream in non-object mode is piping to output as is
- A Stream in object mode is piping to output as an array of objects
Comparison with other solutions (benchmark)
info(value[, replacer[, space[, options]]])
value
, replacer
and space
arguments are the same as for JSON.stringify()
.
Result is an object:
{
minLength: Number, // mininmal bytes when values is stringified
circular: [...], // list of circular references
duplicate: [...], // list of objects that occur more than once
async: [...] // list of async values, i.e. promises and streams
}
Options:
async
Type: Boolean
Default: false
Collect async values (promises and streams) or not.
continueOnCircular
Type: Boolean
Default: false
Stop walking through a value or not whenever circular reference is found. Setting option to true
allows to find all circular references.
License
MIT