Fork me on GitHub

Try SpahQL

Examples

Select from an object by path:

/hash/subhash

Select from an array:

/arr1/0
/arr2/1
/arr1/2
...

Select from an array of objects:

/arrayofobjects/0/a

Select recursively by path:

/arrayofobjects//a //-> all "a" keys in /arrayofobjects

Select all keys in an object:

/hash1/* //-> all keys from /hash1

Select all matching a criteria:

//*[/.type == 'array'][/.size > 0] //-> all non-empty arrays

Set literals:

{"extra string", /arr1/0, /arr2/*} //-> A single set containing a string literal, the first item from /arr1 and all items from /arr2

Basic literals:

3
"three"
true
false

Properties:

/.size //-> Number of keys on the root object
/arr1/.size //-> Length of /arr1
/arr1/0/.size //-> Length of string at /arr1/0

/arr1/.type //-> "array"
/.type //-> "object"

Basic equalities:

/hash1/a == "does the value match this?"
/hash1 == /hash2 //-> will be compared recursively

Basic inequalities:

/arr1/.size > 10 //-> /arr1 longer than 10 items?
/arr1/0/.size <= 100 //-> /arr/0 is 100 characters or less?

Rough equalities:

/hash1/a =~ "^value matches this regex\?"

Supersets:

//a }>{ "is there an "a" key matching this?"

Subsets:

/hash1/a }<{ {"does", "the", "value", "match", "any of these?"}

Joint sets:

//a }~{ {"any", "'a' keys", "matching", "any of these?"}

Disjoint sets:

//a }!{ {"none of the", "'a' keys", "match", "any of these"}