Netcat输出pipe道,jsonparsing

我想要的是这样的:

  • netcat到服务器,streamjson格式的loglines。
  • 将nc的输出pipe道输出为“东西”,以某种可定制的格式(像Perl或Python这样的东西)来将json格式化为纯文本格式。
  • 允许“某事”是可以理解的。

我将nc的输出pipe道输出到别的东西的小尝试导致服务器输出“Broken pipe”。

我开始看python的JSON处理器,开始你可以格式化它“漂亮”的风格:

| python -mjson.tool

有很多人在这方面延伸,这里有一些 例子 。

我使用jq在命令行上parsingJSON。 我知道你的问题要求以纯文本的方式呈现,但我认为这更接近你想要完成的事情。

例如:

 {"chef_server": { "server_url": "http://localhost:4000" },"run_list": [ "recipe[apt::default]", "recipe[build-essential::default]", "recipe[chef-server::rubygems-install]" ] } 

可以parsing产生:

  tristan.local]$ ~ cat chef.json| jq -c '.run_list[]' "recipe[apt::default]" "recipe[build-essential::default]" "recipe[chef-server::rubygems-install]" 

看看这个教程 ,这非常有用。