[DJSON-18] Fast way to print indented json Created: 15/Dec/14 Updated: 15/Dec/14
Formatted json is very handy for human consumption, for example, while debugging or exploring JSON API. data.json offers formatting in a form of pprint-json. Problem is, pprint-json is dead slow because it tries to fit everything within some line width limit. In practice it takes 20-100 times more time to use pprint-json instead of write-str, up to the point where it just cannot be used in production:
Proposed enhancement is very simple: indent new keys and array elements, but do not try to fit values into line width limit. For human, JSON formatted this way is still easy consumable, structure is evident. The only downside is that some lines might become very long.
In a patch attached, I modified write-array and write-object, added new :indent option to write. To print indented json, one can write now: (write-str data :indent true)
There's some performance penalty, of course, but relatively small:
I also fixed small bug: (seq m) thing in write-object should be (seq x).