spray / spray-json

A lightweight, clean and simple JSON implementation in Scala
Apache License 2.0
974 stars 190 forks source link

Added method for sorted print #164

Closed mattinbits closed 7 years ago

mattinbits commented 9 years ago

This method prints in the same format as PrettyPrinter but sorts the keys of each object lexicographically.

The impetus for this change was this question: http://stackoverflow.com/questions/31418626/sort-fields-in-rendered-json

In general it is useful to be able to have more deterministic control over the ordering of output, if diff tools are to be used.

As per the README, I'm happy to license the work to the spray-json project under the project’s open source license. Wasn't sure what to put as a licence header in each file. If you let me know, I'll update the PR accordingly.

ktoso commented 7 years ago

Resolves https://github.com/spray/spray-json/issues/224

tonyamelnychuk commented 5 years ago

Hi guys, should CompactPrinter also has such ordering?

mattinbits commented 5 years ago

Hi @tonyamelnychuk it was not a goal of this PR to do that, but I can imagine this could be useful functionality in other use cases. Given this is an old, closed PR, the best course of action may be to create a new issue or PR for the requirement.