tidwall/pretty

Indentation size and sorting

kseistrup opened this issue · 2 comments

Perhaps it would be useful with two optional parameters: sort (boolean) and indent (integer or string).

A version of the example with indentation=2 and sorted keys could look like this:

{
  "age": 37,
  "children": [
    "Sara",
    "Alex",
    "Jack"
  ],
  "fav.movie": "Deer Hunter",
  "friends": [
    {
      "age": 44,
      "first": "Janet",
      "last": "Murphy"
    }
  ],
  "name": {
    "first": "Tom",
    "last": "Anderson"
  }
}

Thanks for the suggestion. Sorting would be a nice option.

Right now there's a PrettyOptions(json, opt) function that allows for providing the indentation and also the max-width for single line arrays.

I just pushed an update that allows for sorting keys on objects.