{"id":2197,"date":"2011-07-29T21:30:18","date_gmt":"2011-07-29T20:30:18","guid":{"rendered":"http:\/\/www.devco.net\/?p=2197"},"modified":"2011-08-01T20:18:01","modified_gmt":"2011-08-01T19:18:01","slug":"rich-data-on-the-cli","status":"publish","type":"post","link":"https:\/\/www.devco.net\/archives\/2011\/07\/29\/rich-data-on-the-cli.php","title":{"rendered":"Rich data on the CLI"},"content":{"rendered":"

I’ve often wondered how things will change in a world where everything is a REST API and how relevant our Unix CLI tool chain will be in the long run. I’ve known we needed CLI ways to interact with data – like JSON data – and have given this a lot of thought.<\/p>\n

MS Powershell does some pretty impressive object parsing on their CLI but I was never really sure how close we could get to that in Unix. I’ve wanted to start my journey with the grep<\/em> utility as that seemed a natural starting point and my most used CLI tool.<\/p>\n

I have no idea how to write parsers and matchers but luckily I have a very talented programmer working for me<\/a> who were able to take my ideas and realize them awesomely. Pieter wrote a json grep and I want to show off a few bits of what it can do.<\/p>\n

I’ll work with the document below:<\/p>\n

\r\n[\r\n  {\"name\":\"R.I.Pienaar\",\r\n   \"contacts\": [\r\n                 {\"protocol\":\"twitter\", \"address\":\"ripienaar\"},\r\n                 {\"protocol\":\"email\", \"address\":\"rip@devco.net\"},\r\n                 {\"protocol\":\"msisdn\", \"address\":\"1234567890\"}\r\n               ]\r\n  },\r\n  {\"name\":\"Pieter Loubser\",\r\n   \"contacts\": [\r\n                 {\"protocol\":\"twitter\", \"address\":\"pieterloubser\"},\r\n                 {\"protocol\":\"email\", \"address\":\"foo@example.com\"},\r\n                 {\"protocol\":\"msisdn\", \"address\":\"1234567890\"}\r\n               ]\r\n  }\r\n]<\/pre>\n

There are a few interesting things to note about this data:<\/p>\n