JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 16349339
  • Score
    100M100P100Q237116F
  • License MIT

A set of utilities that extend the use of JSON

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

NPM version Build Status Coverage Status

A set of utilities that extend the use of JSON.

Features:

  • Value info: stringifyInfo()
  • Stringify stream: stringifyStream()
  • TBD Parse stream
  • TBD Support for circular references
  • TBD Binary representation

Install

npm install @discoveryjs/json-ext

API

  • [stringifyStreamvalue[, replacer[, space]]](#stringifystreamvalue-replacer-space)
  • [stringifyInfovalue[, replacer[, space[, options]]]](#stringifyinfovalue-replacer-space-options)

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 when JSON.stringify() returns undefined (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)

stringifyInfo(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 collecting info for a value or not whenever circular reference is found. Setting option to true allows to find all circular references.

License

MIT