Socket
Socket
Sign inDemoInstall

json-superstring

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    json-superstring

Fast, safe JSON stringification.


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Install size
4.35 kB
Created
Weekly downloads
 

Changelog

Source

1.0.0

  • Initial release.

Readme

Source

json-superstring

The native JSON.stringify() method is quite fast, but it lacks safety checks for things like circular references and getter properties that throw errors. The json-superstring module wraps JSON.stringify(), and includes safety checks for these potentials issues.

Usage

Add json-superstring as a dependency in package.json:

$ npm install json-superstring -S

Then simply call json-superstring...

const jsonSuperstring = require('json-superstring');

const data = {
  foo: {
    a: '1',
    b: 2
  }
};
data.foo.bar = data.foo;

console.log(jsonSuperstring(data));
// prints: {"foo":{"a":"1","b":2,"bar":"[Circular]"}}

API

  • jsonSuperstring(data [, options]): Stringifies a value in the same manner as JSON.stringify(), but prevents circular reference errors.

    Parameters include:

    • data: (required) the data to stringify.

    • options: (optional) an object to customize various behavioral aspects of json-superstring. Keys include:

      • space: (optional) a String or Number to pass as JSON.stringify()'s space parameter. Defaults to undefined.

      • checkProps (optional) a Boolean indicating whether or not json-superstring should perform safety checks on getter properties. Only enable if absolutely necessary, as this check requires an additional pass over all keys on an object. Not all use cases require this check, and leaving it turned off can dramatically improve performance. Defaults to false.

Motivation

There are a number of safe JSON stringify modules out there, and this module has drawn inspiration from them (primarily safe-json-stringify). However, the bulk of them focus on ensuring compatibility with the broadest set of legacy browsers as possible. This module is focused on usage within Node.js, and, so, can take advantage of a number of various structures in ECMA Script 2015 that significantly boost performance without working about legacy browser support.

Keywords

FAQs

Last updated on 09 Jan 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