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

Already on GitHub? Sign in to your account

Format json in line #114

freewind opened this Issue May 22, 2012 · 3 comments


None yet
3 participants

At present, jsbeautify will format json into multi-lines. For example:

var items = nativeUsers.find({ email: 'aaa@aaa.com' }, _).toArray(_);

will be formatted as:

var items = nativeUsers.find({
    email: 'aaa@aaa.com'
}, _).toArray(_);

But I think it's kept inline will be better for this code.

Will jsbeautify handle it like this:

  1. if { is at the line end, it will be formatted into multi-lines:

    var items = nativeUsers.find({
                       email: 'aaa@aaa.com' }, _).toArray(_);
  2. if not, format them inline

So, we can control if the json be formatted inline or multiline


einars commented May 22, 2012

  1. if { is at the line end, it will be formatted into multi-lines:
  2. if not, format them inline

That's a good idea, but, sadly, this wouldn't work good at all. The
beautifier is used extremely often to unpack packed/compressed/minified
scripts, and this would mean that for packed scripts/jsons/etc, even
the large objects are always formatted inline.

The proper solution, I guess, would be seeing physically how many items
are there inside the object, and deciding the formatting on that, but I
don't see how to do that nicely in the current implementation :(


At least we can provide such a configuration, and by default it's disabled, so it won't change the behavior of current.

But if I enable it, it will work as I described above.

I think it's very useful when I use jsbeautifier as my javascript formatter when coding -- which I have fully control of my code.


bitwiseman commented Apr 28, 2013

I agree there are scenarios where this would be nice, but to handle them right (even in a configuration only case) would require significant work - see #200 for related discussion. If you can find a way to do it and add the tests, submit a pull request and we can discuss.

@bitwiseman bitwiseman modified the milestone: v1.6.0, Future Jan 26, 2016

@bitwiseman bitwiseman added a commit that referenced this issue Jan 26, 2016

@bitwiseman bitwiseman Destructuring, importing, and short objects
Fixes #114
Fixes #315
Fixes #370
Fixes #382

@bitwiseman bitwiseman closed this in #853 Jan 26, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment