@sroberts advanced persistent incident responder

Pretty JSON is Pretty (Useful)

So as initially suggested I haven’t been good about blogging yet. I’ve been quite busy with work. But I did want to pass along one small tip I’ve picked up.

A lot of the work I’ve been doing has been a combination of Ruby/Python and command line data parsing. In much of this shell I’m working through JSON documents on the command line, often using commands like:

cat foo.txt | grep "foo" | sort | uniq

I’ve learned a lot about composing commands and the beauty of the Unix philosophy, it’s been great. But I hit a lot of issues with some tools that initially spit out “ugly”, overly terse JSON:

[{"foo": "foo", "bar": [1, 2, 3], "baz": "baz"}]

Valid? Yes, but difficult to work with, especially on the command line with the simple grep commands I was using. I got close to writing a tool to use Python or Ruby’s built in conversion until I found:

cat foo_ugly.json | python -tmjson.tool > foo_pretty.json

Which spit out the far easier to read and work with:

[
  {
    "foo": "foo",
    "bar": [1, 2, 3],
    "baz": "baz"
  }
]

Just a little tip if you’re also using lots of JSON on the command line.


So a number of people were kind enough to respond on Twitter to my post on this and recommend I look into ./jq, which describes itself as “jq is like sed for JSON data”. I’ve played with it a bit and must say it seems like a very cool tool that could certainly help with what I’m doing. I’m going to use it for a few days, dig into it more, and maybe post a follow up.

Thanks @danthompson, @pengynn, & @1stvamp!

My First New Post

So after a lot of harassment by the likes of Ben Balter and some other GitHubber’s I’ve decided it’s a good time to learn Jekyll and GitHub Pages, along with the wonderful Hyde library for style points, and start a blog. I’ve largely been terrible about blogging, but frankly I think I’ve never had quite such a good handle on what interests me and how to talk about it, so here’s hoping this one goes better.

I’m hoping to share:

  • Some developing ideas
  • Projects I’ve been working on
  • Improve my writing
  • Things I’ve been learning/trying to learn
  • And responding in longer form to a few other folks on the Internet

So hit me up on Twitter (@sroberts) and let me know what you think.