Skip to content
Stringify an object/array like JSON.stringify just without all the double-quotes
JavaScript
Latest commit 8ccbf19 Mar 19, 2016 @SBoudrias SBoudrias Merge pull request #32 from searls/fix-arrays
Guards against cyclic values in arrays
Failed to load latest commit information.
.editorconfig minor tweaks May 9, 2015
.gitattributes init Dec 11, 2012
.gitignore Use `files` property in package Jun 5, 2013
.jshintrc minor tweaks May 8, 2015
.travis.yml Update .travis.yml Feb 8, 2015
LICENSE Add a license file Jan 14, 2016
contributing.md init Dec 11, 2012
fixture.js escape newlines in strings - fixes #21 Jul 28, 2015
index.js Fixes #24 Mar 18, 2016
package.json 2.3.1 Nov 7, 2015
readme.md Update readme copyright notice Jan 14, 2016
test.js Fixes #24 Mar 18, 2016

readme.md

stringify-object Build Status

Stringify an object/array like JSON.stringify just without all the double-quotes.

Useful for when you want to get the string representation of an object in a formatted way.

It also handles circular references and lets you specify quote type.

Install

$ npm install --save stringify-object

Usage

var obj = {
    foo: 'bar',
    'arr': [1, 2, 3],
    nested: { hello: "world" }
};

var pretty = stringifyObject(obj, {
    indent: '  ',
    singleQuotes: false
});

console.log(pretty);
/*
{
    foo: "bar",
    arr: [
        1,
        2,
        3
    ],
    nested: {
        hello: "world"
    }
}
*/

API

stringifyObject(input, [options])

Circular references will be replaced with "[Circular]".

input

Required
Type: object, array

options

indent

Type: string
Default: '\t'

Choose the indentation you prefer.

singleQuotes

Type: boolean
Default: true

Set to false to get double-quoted strings.

filter(obj, prop)

Type: function

Expected to return a boolean of whether to keep the object.

License

BSD license © Yeoman Team

Something went wrong with that request. Please try again.