Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
spec
README.rdoc
Rakefile
VERSION
jsonpath.gemspec

README.rdoc

Jsonpath

This is an implementation of goessner.net/articles/JsonPath/.

Usage

wrapper = JsonPath.wrap(JSON.parse(<<-HERE_DOC))
{"store": 
  {"bicycle":
    {"price":19.95, "color":"red"},
    "book":[
      {"price":8.95, "category":"reference", "title":"Sayings of the Century", "author":"Nigel Rees"},
      {"price":12.99, "category":"fiction", "title":"Sword of Honour", "author":"Evelyn Waugh"},
      {"price":8.99, "category":"fiction", "isbn":"0-553-21311-3", "title":"Moby Dick", "author":"Herman Melville"},
      {"price":22.99, "category":"fiction", "isbn":"0-395-19395-8", "title":"The Lord of the Rings", "author":"J. R. R. Tolkien"}
    ]
  }
}
HERE_DOC

wrapper.path('$..price').to_a
=> [19.95, 8.95, 12.99, 8.99, 22.99]

wrapper.path('$..author').to_a
=> ["Nigel Rees", "Evelyn Waugh", "Herman Melville", "J. R. R. Tolkien"]

wrapper.path('$..book[::2]').to_a
=> [{"price"=>8.95, "category"=>"reference", "author"=>"Nigel Rees", "title"=>"Sayings of the Century"}, {"price"=>8.99, "category"=>"fiction", "author"=>"Herman Melville", "title"=>"Moby Dick", "isbn"=>"0-553-21311-3"}]
Something went wrong with that request. Please try again.