Socket
Socket
Sign inDemoInstall

json-yieldify

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    json-yieldify

an async JSON.stringify that yields periodically to the event loop


Version published
Weekly downloads
3
increased by200%
Maintainers
1
Install size
23.6 kB
Created
Weekly downloads
 

Readme

Source

node-json-yieldify

An async JSON.stringify that yields periodically to the event loop.

const JsonYieldify = require('json-yieldify');

JsonYieldify.stringify({greetings: 'Hello!'}, (err, json) => {
  if (err) return cb(err);
  // json = {"greetings":"Hello!"}
});

Installation

$ npm install json-yieldify

Features

  • JSON.stringify that doesn't block the event loop
  • Supports the replacer argument
  • Supports the space argument (pretty-print)
  • Handles arbitrarily complex arrays and object graphs

Planned

  • Readable stream signature
  • Writeable stream signature (like JSONStream, but the values can be aribtrarily large)

API

A single function is exported.

JsonYieldify.stringify(value[, replacer[, space]], cb)

The first three arguments are identical to the native JSON.stringify. The final argument is a Node-style callback (e.g. (err, json) =>).

See here for an explanation of the JSON.stringify arguments.

Mutating the value while the function is running results in undefined behavior.

Alternatives

There are some other options in this space that may better meet your requirements.

  • If you are streaming a large array of small JavaScript values (e.g. rows from a Postgres table), you should use JSONStream.

Keywords

FAQs

Last updated on 31 Mar 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc