1

I am working with a KeystoneJS project whose log output looks like this:

enter image description here

If I cut it out and paste into my IDE (WebStorm) I can edit it so that it pretty prints nicely and I can read it much more easily

enter image description here

Is there a way to have iTerm2 automatically do this pretty-printing of all JSON written to screen? A plugin, a setting I've missed, or...? (I have no control over how KeystoneJS prints the log).

Cerulean
  • 5,543
  • 9
  • 59
  • 111
  • Possible duplicate of https://stackoverflow.com/questions/352098/how-can-i-pretty-print-json-in-a-shell-script – El. Apr 29 '20 at 14:32
  • I saw https://stackoverflow.com/questions/352098/how-can-i-pretty-print-json-in-a-shell-script -- not sure if that answers this question for two reasons: 1) they're talking about a shell script, not something integrated into the terminal app itself, although perhaps there's a way to do that, 2) it requires python, which I don't know that well, so looking for another avenue. Perhaps one doesn't need to know it well to implement that solution, but I thought it didn't really answer my question fully. – Cerulean Apr 29 '20 at 15:23

1 Answers1

1

I developed a command line tool to view json log (see https://github.com/qiangyt/jog). It is just like 'tail -f log-file' but it's for json log.

The output is not pretty-printed JSON, instead, it outputs regular flat lines. So it seems not exactly matches your needs, but if your target is just to easily view JSON log line, I guess it is useful for you. If not, let me know, it's easy and happy for me to add a new feature.

It's written using GO, and the cross-platform binaries are downloadable via https://github.com/qiangyt/jog/releases.

Not document how to configure it very well, but it works properly by default,and I'm happy to get issue report or new feature request.

  • OP doesn't seem to have a problem printing JSON. The pretty print is key to what is being asked for here, I think. – General Grievance Jul 19 '20 at 17:39
  • @Calculuswhiz, I think the question is about to pretty print the json log lines. For a single line of json, there're already many tools to do that. My answer is focus on multiple lines of json log, which is not valid json so cannot be recognized then pretty printed by regular json tools, for example, the log lines could be: {"level":"warn", "msg": "..."} \n {"level":"error", "msg": "another message"}. – Yiting Qiang Jul 19 '20 at 18:32