{"_id":"json-prune","_rev":"8-64395f566da218f643963721b8c35693","name":"json-prune","dist-tags":{"latest":"1.2.0"},"versions":{"1.0.0":{"name":"json-prune","version":"1.0.0","keywords":["JSON","pruning","stringify"],"author":{"url":"http://dystroy.org","name":"Denys Séguret","email":"denys.seguret@gmail.com"},"license":"ISC","_id":"json-prune@1.0.0","maintainers":[{"name":"dystroy","email":"denys.seguret@gmail.com"}],"homepage":"https://github.com/Canop/JSON.prune#readme","bugs":{"url":"https://github.com/Canop/JSON.prune/issues"},"dist":{"shasum":"2c7dd8122d68daf53524a75ad7a78036c1b65967","tarball":"https://registry.npmjs.org/json-prune/-/json-prune-1.0.0.tgz","integrity":"sha512-twoIRlgzdZqcmMpk3u68py+G4sxD2dKOB9dRIyv0QB9yzHAyR8LfzMstdVX3tESTE8NfBmrtPGsIQ1u6T6xMZw==","signatures":[{"sig":"MEQCIBOJuauUOQIu2/dPnjrytGPhtGPb7sW+dZ3rk64Q4gEWAiAS7TMNZ+YvCsWRJyMWgZmNTVyrJ7mKrKWO/U4SasHIow==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"JSON.prune.js","_from":".","_shasum":"2c7dd8122d68daf53524a75ad7a78036c1b65967","gitHead":"5c743bb0784ea7638e6fa59f349544ecf50c8594","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"_npmUser":{"name":"dystroy","email":"denys.seguret@gmail.com"},"repository":{"url":"git+https://github.com/Canop/JSON.prune.git","type":"git"},"_npmVersion":"2.14.2","description":" pruning JSON.stringify for the very specific cases where you need to stringify big or recursive javascript objects and don't really need the result to be complete","_nodeVersion":"5.0.0-pre","directories":{}},"1.0.1":{"name":"json-prune","version":"1.0.1","keywords":["JSON","pruning","stringify"],"author":{"url":"http://dystroy.org","name":"Denys Séguret","email":"denys.seguret@gmail.com"},"license":"ISC","_id":"json-prune@1.0.1","maintainers":[{"name":"dystroy","email":"denys.seguret@gmail.com"}],"homepage":"https://github.com/Canop/JSON.prune#readme","bugs":{"url":"https://github.com/Canop/JSON.prune/issues"},"dist":{"shasum":"b7f3e299877c334930fc3afff3237a33eaa5be88","tarball":"https://registry.npmjs.org/json-prune/-/json-prune-1.0.1.tgz","integrity":"sha512-Pt/CSjmWwrPug9Q7fPvKCtSghAQa27Mg39wIPkk7LC6HYf9yHhJClEv11VbthcDmK4lTpR8Y+PJbmnpB4bTP3Q==","signatures":[{"sig":"MEQCIBq1ZjF/+JkYHHVKmRTsHf4l8ulpvz79WaoKWLN048i/AiBdCKKz82yfXvU0h6lha+gljASdLzfyuf+BHHd3yMgElA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"JSON.prune.js","_from":".","_shasum":"b7f3e299877c334930fc3afff3237a33eaa5be88","gitHead":"8eb6ace7a265f2ea05e9a078d52f0a87d6514a19","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"_npmUser":{"name":"dystroy","email":"denys.seguret@gmail.com"},"repository":{"url":"git+https://github.com/Canop/JSON.prune.git","type":"git"},"_npmVersion":"2.14.2","description":" pruning JSON.stringify for the very specific cases where you need to stringify big or recursive javascript objects and don't really need the result to be complete","_nodeVersion":"5.0.0-pre","directories":{}},"1.1.0":{"name":"json-prune","version":"1.1.0","keywords":["JSON","pruning","stringify"],"author":{"url":"https://dystroy.org","name":"Denys Séguret","email":"denys.seguret@gmail.com"},"license":"ISC","_id":"json-prune@1.1.0","maintainers":[{"name":"dystroy","email":"denys.seguret@gmail.com"}],"homepage":"https://github.com/Canop/JSON.prune#readme","bugs":{"url":"https://github.com/Canop/JSON.prune/issues"},"dist":{"shasum":"23e2fad108932b255050e3f1a70500c2b4aa30c7","tarball":"https://registry.npmjs.org/json-prune/-/json-prune-1.1.0.tgz","integrity":"sha512-xpzoTXFWFtRWHcxyBZ8v8NHuLaSBFqUnl/4HDqvnxTA6QTwCSlGM0bl/BHLRVtml0n8wcYmEjKzq2iGBaOUW3g==","signatures":[{"sig":"MEYCIQDkuF+yfSdf9LhSqeCddOSjCuhPL1NDAkR2QNWWo1ZszgIhAPiZuSdRL/lsyUrJEoqYEGGqA2c005AUTHDz4VsKdJlb","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"JSON.prune.js","_from":".","_shasum":"23e2fad108932b255050e3f1a70500c2b4aa30c7","gitHead":"e77331ad5a2adc157f86c92b3a2059e8490530cf","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"_npmUser":{"name":"dystroy","email":"denys.seguret@gmail.com"},"repository":{"url":"git+https://github.com/Canop/JSON.prune.git","type":"git"},"_npmVersion":"4.2.0","description":" pruning JSON.stringify for the very specific cases where you need to stringify big or recursive javascript objects and don't really need the result to be complete","_nodeVersion":"7.9.0","_npmOperationalInternal":{"tmp":"tmp/json-prune-1.1.0.tgz_1499160325032_0.26009303564205766","host":"s3://npm-registry-packages"},"directories":{}},"1.2.0":{"name":"json-prune","version":"1.2.0","description":" pruning JSON.stringify for the very specific cases where you need to stringify big or recursive javascript objects and don't really need the result to be complete","main":"JSON.prune.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git+https://github.com/Canop/JSON.prune.git"},"keywords":["JSON","pruning","stringify"],"author":{"name":"Denys Séguret","email":"denys.seguret@gmail.com","url":"https://dystroy.org"},"license":"MIT","bugs":{"url":"https://github.com/Canop/JSON.prune/issues"},"homepage":"https://github.com/Canop/JSON.prune#readme","gitHead":"05a8cc4c2310f370a8820ec0229f7096dc186c1e","_id":"json-prune@1.2.0","_nodeVersion":"24.11.1","_npmVersion":"11.6.2","dist":{"integrity":"sha512-fVCYCKpHt8uA0bxY79muv847+WkvNJbyzt2B745i4REqBJlI5OH10mSwhut+828G7SketkCTFZIj08uKWsl1YA==","shasum":"b07b4689e81dbbdcd3d5463b87187b44e8744c35","tarball":"https://registry.npmjs.org/json-prune/-/json-prune-1.2.0.tgz","fileCount":6,"unpackedSize":16419,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCHBrnqyHweKeheo4hGCPRSWwAyH4Rnqed5PjvemIcEzQIhAMdAiwt0dYWCqXxeGK/ZvsXDg/QkCUbsaqjoL+ZdynBr"}]},"_npmUser":{"name":"dystroy","email":"denys.seguret@gmail.com"},"directories":{},"maintainers":[{"name":"dystroy","email":"denys.seguret@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/json-prune_1.2.0_1771700469818_0.13089357409558366"},"_hasShrinkwrap":false}},"time":{"created":"2015-09-15T18:23:10.537Z","modified":"2026-02-21T19:01:10.084Z","1.0.0":"2015-09-15T18:23:10.537Z","1.0.1":"2015-10-30T07:15:22.681Z","1.1.0":"2017-07-04T09:25:26.007Z","1.2.0":"2026-02-21T19:01:09.966Z"},"bugs":{"url":"https://github.com/Canop/JSON.prune/issues"},"author":{"name":"Denys Séguret","email":"denys.seguret@gmail.com","url":"https://dystroy.org"},"license":"MIT","homepage":"https://github.com/Canop/JSON.prune#readme","keywords":["JSON","pruning","stringify"],"repository":{"type":"git","url":"git+https://github.com/Canop/JSON.prune.git"},"description":" pruning JSON.stringify for the very specific cases where you need to stringify big or recursive javascript objects and don't really need the result to be complete","maintainers":[{"name":"dystroy","email":"denys.seguret@gmail.com"}],"readme":"JSON.prune\n==========\n\n[![Chat on Miaou](https://miaou.dystroy.org/static/shields/room-en.svg?v=1)](https://miaou.dystroy.org/8?Javascript)\n[![Chat on Miaou](https://miaou.dystroy.org/static/shields/room-fr.svg?v=1)](https://miaou.dystroy.org/3?Code_Croissants)\n\nJSON.prune is a pruning `JSON.stringify` for the very specific cases where you need to stringify big or recursive javascript objects and don't really need the result to be complete.\n\n    var json = JSON.stringify(window); // fails\n    var json = JSON.prune(window); // builds a JSON valid string from a pruned version of the\n                                   // recursive, deep, and not totally accessible window object\n    var prunedWindow = JSON.parse(JSON.prune(window)); // builds a lighter acyclic version of window\n\nJSON.prune also lets you, in case of need, stringify inherited and/or non enumerable properties.\n\n\tJSON.prune(window.location, {inheritedProperties:true}); // without inherited properties, FireFox and IE only show an empty object\n\nJSON.prune.log is a proxy over console.log deep cloning the objects (using JSON.prune) before logging them, in order to avoid the delay problem encountered on non primitive objects logging.\n\nYou should not use it frequently, only when you really need to see the objects how they were at logging time.\n\n    // make sure someObject is logged as it was at logging time\n    JSON.prune.log(someObject);\n\nProject/Test page\n-----------------\n\n[dystroy.org/JSON.prune](http://dystroy.org/JSON.prune)\n\nInclude it in a page\n-------------------\n\n\t<script src=http://dystroy.org/JSON.prune/JSON.prune.js></script>\n\nUse it with CommonJS or in node\n-------------------------------\n\n\tvar prune = require('json-prune');\n\tvar json = prune(obj);\n\nDiscussions\n-----------\n\n[JavaScript room on Miaou](https://dystroy.org/miaou/8)\n\nCustomization: replace the \"-pruned-\" placeholder\n-------------------------------------------------\n\nHere's how are handled by default by JSON.prune the special values needing pruning:\n\nValue | Default\n------|--------\n`undefined` | Key and value are ommited (same as `JSON.stringify`)\nfunction | Key and value are ommited (same as `JSON.stringify`)\nalready written or too deep object (cycle prevention) | The `\"-pruned-\"` string\narray with too many elements | Truncation: `JSON.prune` applied to only the start of the array\n\nBy specifiying a `replacer` or a `prunedString` in `JSON.prune` options, you can customize those prunings.\n\nThe `replacer` function takes 4 arguments:\n* the value to replace\n* the default replacement value\n* a boolean indicating whether the replacement is due to a cycle detection (`true` for circular, `false` otherwise)\n* a string indicating the reason for pruning: `'circular'` for circular references, `'depth'` for max depth reached, or `undefined` for other cases (e.g. `undefined` values, functions, array truncation)\n\nReturning `undefined` makes `JSON.prune` ommit the property (name and value).\n\nThe default value makes it easy to just specify the specific behavior you want instead of implementing the whole standard replacement.\n\n### Example 1: Use an object instead of a string as pruning mark\n\n\n\tvar json = JSON.prune(obj, {prunedString: '{}' });\n\nNote: if you want a string to be inserted, don't forget the double quotes, as in `'\"-pruned-\"'`.\n\n### Example 2: Silent Pruning\n\nIf you want the pruned properties to just be ommited, pass `undefined` as `prunedString`:\n\n\tvar obj = {a:3};\n\tobj.self = obj;\n\tvar json = JSON.prune(obj);\n\tconsole.log(json); // logs {\"a\":3,\"self\":\"-pruned-\"}\n\tjson = JSON.prune(obj, {prunedString: undefined });\n\tconsole.log(json); // logs {\"a\":3}\n\nNote: You get the same behavior with\n\n\tjson = JSON.prune(obj, {replacer: function(){}});\n\n### Example 3: Verbose Pruning\n\n\tvar options = {replacer:function(value, defaultValue, circular, reason){\n\t\tif (reason === 'circular') return '\"-circular-\"';\n\t\tif (reason === 'depth') return '\"-too-deep-\"';\n\t\tif (value === undefined) return '\"-undefined-\"';\n\t\tif (Array.isArray(value)) return '\"-array('+value.length+')-\"';\n\t\treturn defaultValue;\n\t}};\n\tvar json = JSON.prune(obj, options);\n\nNote: the `circular` boolean (third argument) is kept for backward compatibility. The `reason` string (fourth argument) provides more granular information: `'circular'` for circular references, `'depth'` for max depth reached.\n\n### Example 4: Function \"serialization\"\n\n\tvar options = {replacer:function(value, defaultValue){\n\t\tif (typeof value === \"function\") return JSON.stringify(value.toString());\n\t\treturn defaultValue;\n\t}};\n\tvar json = JSON.prune(obj, options);\n\n### Example 5: Array truncation mark\n\nThe default behavior on big arrays is to silently write only the first elements. It's possible with a `replacer` to add a string as last element:\n\n\tvar obj = {arr: Array.apply(0,Array(100)).map(function(_,i){ return i+1 })}\n\tfunction replacer(value, defaultValue){\n\t\tif (Array.isArray(value)) return defaultValue.replace(/]$/, ',\"-truncated-\"]');\n\t\treturn defaultValue;\n\t}\n\tvar json = (asPrunedJSON(obj, {arrayMaxLength:5, replacer});\n\nThis produces\n\n\t{\"arr\":[1,2,3,4,5,\"-truncated-\"]}\n\nLicense\n-------\n\nMIT\n","readmeFilename":"README.md","users":{"cdokolas":true}}