JSON.prune icon indicating copy to clipboard operation
JSON.prune copied to clipboard

support for indentation?

Open sandgupta23 opened this issue 5 years ago • 1 comments

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?

sandgupta23 avatar Mar 15 '19 17:03 sandgupta23

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'); 

Canop avatar Mar 15 '19 17:03 Canop