Bash – Netcat output pipe, json parsing

bashnetcatpipe

What I want is this:

  • netcat to the server, which streams json formatted loglines.
  • pipe the output of nc to "something" that will format the json as plaintext, in a customizable format (thinking something like perl or python here).
  • allow "something" to be greppable.

My small attempts at piping the output of nc to something else leads to the server outputting "Broken pipe".

Best Answer

I'd start looking at the python JSON processors, to start you can format it in "pretty" style simply:

| python -mjson.tool

and there are many people who have extended on that, here are a few examples.

Related Topic