Skip to content

Instantly share code, notes, and snippets.

@ericmoritz
Created June 1, 2011 03:55
Show Gist options
  • Save ericmoritz/1001764 to your computer and use it in GitHub Desktop.
Save ericmoritz/1001764 to your computer and use it in GitHub Desktop.
/*
Uses http://jsonselect.org/ to select fields from a riak object
*/
function map_jsonselect(values, keydata, arg) {
var data = Riak.mapValuesJson(values)[0];
if(typeof arg == "string") {
return JSONSelect.match(arg, data);
} else if(typeof arg == "object") {
var accum = {}
for(key in arg) {
var result = JSONSelect.match(arg[key], data);
if(result.length == 1) {
accum[key] = result[0];
} else {
accum[key] = result;
}
}
return [accum];
}
}
{"inputs": [ ["goog", "2005-05-04"], ["goog", "2005-05-05"]],
"query": [
{"map": {"language": "javascript", "name": "map_jsonselect", "arg": {"high": ".High", "low": ".Low"}}},
{"reduce": {"language": "javascript", "source": "function(v) { return v; }"}}
]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment