Phrogz / NeatJSON

Pretty-print your JSON in Ruby, JS, or Lua with more power than JSON.stringify or JSON.pretty_generate
http://phrogz.net/JS/NeatJSON
MIT License
108 stars 19 forks source link

Closing angle bracket of an Object should also be indented #11

Closed bwl21 closed 8 years ago

bwl21 commented 8 years ago
{
   "a" : {
      "b" : 1,
      "c" : 2
   },
   "b" : {
      "b" : 1,
      "c" : 2
   }
}

Would e easier to read if the closing angle bracket is adjusted to the content

{
   "a" : {
      "b" : 1,
      "c" : 2
       },
   "b" : {
      "b" : 1,
      "c" : 2
       }
}
Phrogz commented 8 years ago

This would be a reasonable formatting option, but not the only or default behavior.

Perhaps an option called indentClose:true? indentLast:true?

Phrogz commented 8 years ago

I've added this feature as indentLast for JavaScript, indent_last for Ruby. You can try it out at http://phrogz.net/JS/NeatJSON/

Phrogz commented 8 years ago

By the way, in case you haven't tried it, you might also prefer the "short" formatting mode (maybe along with some object/array padding). That makes it even easier to see where objects end.

var obj = ["foo","bar",{"dogs":42,"piggies":0,"cats":7},{"jimmy":[1,2,3,4,5],"jammy":3.14159265358979,"hot":"pajammy"}];

neatJSON(obj,{ wrap:30, short:true, aligned:true, padding:1, aroundColon:1 });
// [ "foo",
//   "bar",
//   { "dogs"    : 42,
//     "piggies" : 0,
//     "cats"    : 7 },
//   { "jimmy" : [ 1,2,3,4,5 ],
//     "jammy" : 3.14159265358979,
//     "hot"   : "pajammy" } ]
bwl21 commented 8 years ago

Thanks. Cool to make it an option.