Chef-helpers: deep attribute access by JSONPath

Hi,

FWIW, I've released a new version of chef-helpers.gem - my collection of
utils and extra methods I use in recipes. It's available at

One feature that may be particularly useful (and if it's interesting, it
may be worth extracting to a separate gem) is overloading Chef::Node# to
allow reading nested attributes using JSONPath notation (
http://goessner.net/articles/JsonPath/):

chef > require 'chef-helpers'
 => true
chef > node['$..name']
 => ["portinari-2.local", "Java(TM) SE Runtime Environment", "Java

HotSpot(TM) 64-Bit Server VM", "Darwin"]
chef > node['$.kernel.name']
=> ["Darwin"]

You can read about more sophisticated use cases at
http://3ofcoins.net/2013/07/21/access-chef-nodes-attributes-by-jsonpath/ -
I bump into such situations quite often, and easy access to deep attributes
saves me a lot of effort (and prevents confusing tracebacks if the code is
not defensive enough). I'm curious to hear your thoughts.

-- M

Nice! I didn't know about JsonPath until today, but it sounds really useful
for accessing node attributes, especially in light of the recent
discussions on this list. Like! :slight_smile:
On Jul 22, 2013 12:07 PM, "Maciej Pasternacki" maciej@3ofcoins.net wrote:

Hi,

FWIW, I've released a new version of chef-helpers.gem - my collection of
utils and extra methods I use in recipes. It's available at
GitHub - 3ofcoins/chef-helpers: A collection of helper methods to use in Opscode Chef recipes

One feature that may be particularly useful (and if it's interesting, it
may be worth extracting to a separate gem) is overloading Chef::Node# to
allow reading nested attributes using JSONPath notation (
JSONPath - XPath for JSON):

chef > require 'chef-helpers'
 => true
chef > node['$..name']
 => ["portinari-2.local", "Java(TM) SE Runtime Environment", "Java

HotSpot(TM) 64-Bit Server VM", "Darwin"]
chef > node['$.kernel.name']
=> ["Darwin"]

You can read about more sophisticated use cases at
http://3ofcoins.net/2013/07/21/access-chef-nodes-attributes-by-jsonpath/- I bump into such situations quite often, and easy access to deep
attributes saves me a lot of effort (and prevents confusing tracebacks if
the code is not defensive enough). I'm curious to hear your thoughts.

-- M