django-prettyjson icon indicating copy to clipboard operation
django-prettyjson copied to clipboard

Feature idea/request: sort keys alphabetically

Open Sveder opened this issue 3 years ago • 4 comments

I've been integrating with django-prettyjson and in some of my fields the ability to auto sort by key alphabetically in the parsed ("pretty") view would make it even prettier.

  1. Was this considered?
  2. Would you be open to a PR with a new class that inherit PrettyJson and adds the alphabetic sort?

Thanks for the great library :)

Sveder avatar Feb 16 '21 10:02 Sveder

@kevinmickey wdyt?

Sveder avatar Feb 19 '21 11:02 Sveder

I can certainly understand the desire for alphabetically sorting keys. Perhaps as an option, in case the JSON is very large or other reasons you may not want to sort, but I'd be open to "sorted" being the default value for the option.

In terms of implementing this, I would think you could fork yesmeck/jquery-jsonview to add the option and I would certainly be open to point our dependency to the forked version (notably it is unmaintained, so we are free to use our own fork without a PR being accepted upstream).

Let me know if this makes sense to you, or if you feel there are benefits to making more of the modifications in python.

kevinmickey avatar Feb 21 '21 19:02 kevinmickey

@kevinmickey thanks for the response. Just to make sure I understand what you're saying -

  1. To add alphabetical sorting I'll need to change the way JS that handles actually showing the widget.
  2. This is the unmaintained project - https://github.com/yesmeck/jquery-jsonview/
  3. Which is (minimized) and hardcoded in- https://github.com/kevinmickey/django-prettyjson/blob/b0dedc7a33228b75f31bcf62c5c283c32d136cf9/prettyjson/static/prettyjson/prettyjson.js

Your suggestion is for me to fork the above project, add alphabetical ordering to it, compile and minimize it and open a PR to replace the blob in prettyjson.js with my code?

Sveder avatar Mar 02 '21 21:03 Sveder

Yes, you got it -- we are on the same page. For your step 3, there are several options, but I think your proposal (minimizing and hardcoding in, as we currently do) would be the quickest. To be clear, though, the meat of this task is in editing the jquery-jsonview fork.

kevinmickey avatar Mar 03 '21 05:03 kevinmickey