A pruning JSON.stringify
for the very specific cases where you need to be able to stringify
big or recursive javascript objects and don't really need the result to be complete.
var json = JSON.stringify(window); // this fails
var json = JSON.prune(window); // this builds a JSON valid string from a pruned version of the recursive, deep, and not totally accessible window object
var prunedWindow = JSON.parse(JSON.prune(window)); // this builds a lighter and not recursive version of window
It's totally useless for at least 99% js developpers.
JSON.prune.log
is a proxy over console.log
deep cloning the objects before logging them, in order to avoid the delay problem encountered on non primitive objects logging (see here for example).
JSON.prune.log('some object:', window);
You should not use it frequently, only when you really need to see the objects how they were at logging time.
<script src=http://dystroy.org/JSON.prune/.js></script>
JSON.prune({a:1, b:[1, 2, 3]});
JSON.prune(window);
JSON.prune(window.location,{inheritedProperties: true}); // without this setting, FireFox and IE only show an empty object
var a=[]; for (var i=0;i<1000;i++) {a.push(i<2?1:a[i-2]+a[i-1])} JSON.prune(a, 0, 200);