owtj

1.0.3 • Public • Published

owtj

npm version

A very simple JSON stringifier for NodeJS that takes care or circular references.

Usage

The export of the owtj package is a simple function that takes a JS object and converts it to a JSON string.

const owtj = require('owtj');

var circularObject = {
  a: {
    text: 'Hello'
  }
};

// Set a circular reference to see the output.
circularObject.a.b = circularObject.a;

owtj(circularObject);

//  PRINTS
//  { "a": { "text": "Hello", "b": "[Circular]" } }

Stringify options

The owtj function takes the same parameters as JSON.stringify (in fact, that's what it uses underneath)

const owtj = require('owtj');

var circularObject = {
  a: {
    text: 'Hello'
  }
};

// Set a circular reference to see the output.
circularObject.a.b = circularObject.a;

owtj(circularObject, null, 2);

//  PRINTS
//  { 
//    "a": { 
//      "text": "Hello", 
//      "b": "[Circular]" 
//    } 
//  }

Dependencies (0)

    Dev Dependencies (1)

    Package Sidebar

    Install

    npm i owtj

    Weekly Downloads

    1

    Version

    1.0.3

    License

    MIT

    Unpacked Size

    4.26 kB

    Total Files

    4

    Last publish

    Collaborators

    • flagpoonage