Canop / JSON.prune

A pruning version of JSON.stringify, allowing for example to stringify window or any big or recursive object
MIT License
163 stars 27 forks source link

support for indentation? #10

Open sandgupta23 opened 5 years ago

sandgupta23 commented 5 years ago

Standerted JSON.stringify allows an argument for \t and \n for indentation purposes as follows:


JSON.stringify({ uno: 1, dos: 2 }, null, '\t');
// returns the string:
// '{
//     "uno": 1,
//     "dos": 2
// }'

JSON.prune supports it as well?

Canop commented 5 years ago

At the moment there's no support for improved formatting, and it can't follow the same exact syntax because the second argument is an option object.

This could be modified but I'm not sure there's really a need.

If you're not performance tied, you can use JSON.prune to produce a pruned object then use the standard representation:

let pruned = JSON.parse(JSON.prune(yourObject));
let json = JSON.stringify(pruned, null, '\t');