Project

jamespath

0.01
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Like XPath, but for JSON and other structured objects.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 10.0
< 3.0, >= 2.1.7
~> 0.0
 Project Readme

Jamespath Version Build Status

Jamespath is a library that lets you select objects from deeply nested structures, arrays, hashes, or JSON objects using a simple expression language.

Think XPath, but for objects.

Installing

$ gem install jamespath

Or with Bundler:

gem 'jamespath', '~> 1.0'

Usage

To use Jamespath, call the {Jamespath.search} method with an expression and an object ot search:

object = { foo: { bar: ['value1', 'value2', 'value3'] } }
Jamespath.search('foo.bar[0]', object) #=> 'value1'

You can also {Jamespath.compile} an expression if you are performing the same search operation against multiple objects:

object1 = { foo: { bar: ['value1', 'value2', 'value3'] } }
object2 = { foo: { bar: ['value4', 'value5', 'value6'] } }

expr = Jamespath.compile('foo.bar[0]')
expr.search(object1) #=> 'value1'
expr.search(object2) #=> 'value4'

Expression Syntax

See the JMESpath project for more information on the expression syntax.

License & Acknowledgements

This library was written by Loren Segal and Trevor Rowe and is licensed under the MIT license. The implementation is based on the JMESpath library written by James Sayerwinnie for the Python programming language.