json: (paste then 'parse json' OR use samples:
1
2
3
)
Download a_jsonQuery_01.packed.js (1.7kb packed)
|
item: [optional] if an array of strings, acts like "OR"
attrib: [required] if an array of strings, acts like "AND"
results clear:
|
API
Examples use Sample 1 for json data!
attrib examples string or array of strings ( for 'equal', use '==' - its JS! )
.author=="Herman Melville"
.price>10
.price
[".price>10", ".category=='fiction'"]
- acts like an "AND"
.bicycle.color=="red"
- any valid dot notation should work
.title.indexOf("of the")>0
- yes, even this works
item examples string or array of strings ( empty or '*' returns 'any' )
book
bicycle
["book", "bicycle"]
- acts like an "OR"
function
Namespaced as a_jQ
Only one function: a_jQ.from(jsData_object, item_str, attrib_str)
item can be an empty string, an item(string) or array of items(strings). "*" is same as empty string
attrib is required - can be an attrib(string) or array of attribs(strings). Attrib should start with a dot, like ".name"
examples
var obj= a_jQ.from( jsDataObject, "*", ".price>10" );
var obj= a_jQ.from( jsDataObject, "book", ".price>10" );
var obj= a_jQ.from( jsDataObject, ["book", "bicycle"], ".price>10" );
var obj= a_jQ.from( jsDataObject, ["book", "bicycle"], [".price>10", ".color=='red'"] );
result
success..
{
"results":[ OBJ, OBJ, .. ],
"warnings":[ "xxx", "xxx", .. ]
}
where OBJ= { "obj":object, "path":"xxx.xxx.xx" }
fail..
{
"error":"xxx"
}
about
Not a big believer of keeping a data layer in JS but sometimes it makes sense.
Needed this functionality and found a nice lib called JsonPath and also looked at jaql.
However, wanted something simpler (and faster) than jaql and not so xPath-y like JsonPath, so wrote this thing, but ended up not using it - lol.
|