{"_id":"pretty-json-stringify","_rev":"3822327","name":"pretty-json-stringify","description":"A function that adds customizeable indents to JSON data","dist-tags":{"latest":"0.0.2"},"maintainers":[{"name":"sergets","email":""}],"time":{"modified":"2025-06-26T09:40:02.000Z","created":"2016-08-05T15:56:32.978Z","0.0.2":"2016-11-01T18:00:57.472Z","0.0.1":"2016-08-05T15:56:32.978Z"},"users":{},"author":{"name":"Sergey Tsibulskiy"},"repository":{"type":"git","url":"git+https://github.com/sergets/pretty-json.git"},"versions":{"0.0.2":{"name":"pretty-json-stringify","version":"0.0.2","description":"A function that adds customizeable indents to JSON data","main":"index.js","scripts":{"test":"make test"},"repository":{"type":"git","url":"git+https://github.com/sergets/pretty-json.git"},"keywords":["json","stringify","indents","pretty","print"],"author":{"name":"Sergey Tsibulskiy"},"license":"MIT","bugs":{"url":"https://github.com/sergets/pretty-json/issues"},"homepage":"https://github.com/sergets/pretty-json#readme","devDependencies":{"chai":"^3.5.0","mocha":"^3.0.1"},"gitHead":"7c4f9ced0776b31cf135c287b44c8bc1fe9f3c37","_id":"pretty-json-stringify@0.0.2","_shasum":"dc0f1dbeab6bc1ab15f40d4cce4f38b75b17a334","_from":".","_npmVersion":"3.8.9","_nodeVersion":"6.2.0","_npmUser":{"name":"sergets","email":"sergets@ya.ru"},"dist":{"shasum":"dc0f1dbeab6bc1ab15f40d4cce4f38b75b17a334","size":3699,"noattachment":false,"key":"/pretty-json-stringify/-/pretty-json-stringify-0.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/pretty-json-stringify/download/pretty-json-stringify-0.0.2.tgz"},"maintainers":[{"name":"sergets","email":""}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/pretty-json-stringify-0.0.2.tgz_1478023256872_0.8560462021268904"},"directories":{},"publish_time":1478023257472,"_hasShrinkwrap":false,"_cnpm_publish_time":1478023257472,"_cnpmcore_publish_time":"2021-12-18T19:17:07.894Z"},"0.0.1":{"name":"pretty-json-stringify","version":"0.0.1","description":"A function that adds customizeable indents to JSON data","main":"index.js","scripts":{"test":"make test"},"repository":{"type":"git","url":"git+https://github.com/sergets/pretty-json.git"},"keywords":["json","stringify","indents","pretty","print"],"author":{"name":"Sergey Tsibulskiy"},"license":"MIT","bugs":{"url":"https://github.com/sergets/pretty-json/issues"},"homepage":"https://github.com/sergets/pretty-json#readme","devDependencies":{"chai":"^3.5.0","mocha":"^3.0.1"},"gitHead":"18a77d255411874abbaa0dc2874361c4994f69d3","_id":"pretty-json-stringify@0.0.1","_shasum":"d8da979a3868427c6f557b932807b190a10cbd0b","_from":".","_npmVersion":"3.8.9","_nodeVersion":"6.2.0","_npmUser":{"name":"sergets","email":"sergets@ya.ru"},"dist":{"shasum":"d8da979a3868427c6f557b932807b190a10cbd0b","size":3581,"noattachment":false,"key":"/pretty-json-stringify/-/pretty-json-stringify-0.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/pretty-json-stringify/download/pretty-json-stringify-0.0.1.tgz"},"maintainers":[{"name":"sergets","email":""}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/pretty-json-stringify-0.0.1.tgz_1470412591124_0.6749384321738034"},"directories":{},"publish_time":1470412592978,"_hasShrinkwrap":false,"_cnpm_publish_time":1470412592978,"_cnpmcore_publish_time":"2021-12-18T19:17:08.109Z"}},"readme":"# pretty-json-stringify [![Build Status](https://travis-ci.org/sergets/pretty-json-stringify.svg?branch=master)](https://travis-ci.org/sergets/pretty-json-stringify) [![npm module](https://img.shields.io/npm/v/pretty-json-stringify.svg?style=flat)](https://www.npmjs.com/package/pretty-json-stringify)\nA naive function that adds customizeable indents to JSON data (pretty-prints JSON whitespace).\nYou can define whether any object or array should either be collapsed to one line or expanded with one item on each line.\n\n## Syntax\n````js\nvar JSONString = prettyJSONStringify(objectToStringify, params);\n````\n\n## Example\n````js\nvar prettyJSONStringify = require('pretty-json-stringify');\n\nprettyJSONStringify({\n    simple : [1, 2, 3],\n    tooShort : [4],\n    doNotExpand : [5, 6, 7],\n    level1 : { \n        level2_1 : {\n            a : 1\n        },\n        level2_2containsExpanded : {\n            a : 1,\n            doExpand : ['expanded'] // If any portion of object contains something told to be expanded, parent\n                                    // object is expanded regardless of whether it is told to be expanded itself\n        },\n        level2_3 : {\n            a : 1\n        },\n    }\n}, {\n    shouldExpand : function(object, level, key) {\n        if (key == 'doNotExpand') return false;\n        if (key == 'doExpand') return true;\n        if (Array.isArray(object) && object.length < 2) return false;\n        if (level >= 2) return false;\n        return true;\n    }\n});\n````\nThis returns\n````json\n{\n    \"simple\" : [\n        1,\n        2,\n        3\n    ],\n    \"tooShort\" : [4],\n    \"doNotExpand\" : [5, 6, 7],\n    \"level1\" : {\n        \"level2_1\" : { \"a\" : 1 },\n        \"level2_2containsExpanded\" : {\n            \"a\" : 1,\n            \"doExpand\" : [\n                \"expanded\"\n            ]\n        },\n        \"level2_3\" : { \"a\" : 1 }\n    }\n}\n````\n\nAlso following \"code-style\" parameters can be applied (any passed string is inserted as is, it is user's responsibility to keep it valid whitespace):\n- `tab` (default: 4 spaces)\n- `spaceBeforeColon` (default: 1 space)\n- `spaceAfterColon` (default: 1 space)\n- `spaceAfterComma` (default: 1 space)\n- `spaceInsideObject` (inserted after opening and before closing braces, default: 1 space)\n- `spaceInsideArray` (inserted after opening and before closing braces, default: empty string).\n\nIf `shouldExpand` parameter is not passed, it expands every object whose plain JSON is longer that 25 characters.\n\n","_attachments":{},"homepage":"https://github.com/sergets/pretty-json#readme","bugs":{"url":"https://github.com/sergets/pretty-json/issues"},"license":"MIT"}