Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for indentation? #10

Open
sandgupta23 opened this issue Mar 15, 2019 · 1 comment
Open

support for indentation? #10

sandgupta23 opened this issue Mar 15, 2019 · 1 comment

Comments

@sandgupta23
Copy link

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
Copy link
Owner

Canop commented Mar 15, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants