Skip to content
This repository has been archived by the owner on Mar 31, 2020. It is now read-only.

lsegal/jamespath

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Implements JMESpath declarative object searching. Like XPath, but for JSON and other structured objects.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages