Download Praetor.JS
<script src="//rawgit.com/magnumjs/praetor.js/master/praetor.min.js"></script>
Includes the (bundled) dependency of JSONPath
####Simple Example
JSON:
{"movies":[{"title":"American Sniper"},{"title":"Terminator"}]}
p.proc (
getMovies (),
['$..title'],
'this.results[0].reverse()'
)
Results:
["Terminator","American Sniper"]
####API methods Add a data store.
p.setDataStore( name, data )
Create a named Query on a given dataStore
p.setJsonQuery ( name, JSONPathQuery, storeName )
Execute JSONPath Query by name and get result
getJsonQueryResult ( name, options )
Create a stored proc with a given name, named existing queries, the code to be executed and its default properties (added to the executing context)
p.setStoredProc ( name, namedQueries , codeBody , parms )
Execute a given named stored procedure and pass in overriding default properties and it will return the results.
getStoredProcResult ( name, params )
p.setDataStore('books',{books:[{title:'kids', author:'adams'},{title:'action', author:'johns'}]});
p.setJsonQuery('getBookTitles','$..title', 'books');
console.log(p.getJsonQueryResult('getBookTitles'))
console.log(p.getState())
var code='console.log(this.params, this.results[0]["getBookTitles"]); \
if(this.params.upperCase){ \
this.results[0]["getBookTitles"]=this.results[0]["getBookTitles"].map(function(x) { return x.toUpperCase(); }); \
}';
p.setStoredProc('convertBookTitles',['getBookTitles'],code,{upperCase : false})
console.log(p.getStoredProcResult('convertBookTitles', {upperCase : true })[0]['getBookTitles'])
##Jasmine Specs http://rawgit.com/magnumjs/praetor.js/master/tests/specRunner.html
Created by Michael Glazer 3/1/2015