Open
Description
So currently, running the library works like this:
const { JSONPath } = require('jsonpath-plus')
const query = '<some query>'
const runQuery = (object) => {
return JSONPath({ path: query, json: object })
}
if I run that query multiple times, there are a bunch of initialization steps that it will repeat that it does not need to (class instantiation). I understand that the generated path is cached, but that feels like an internal cache that doesnt need to be managed and guessed at. Why not just change the api like so:
const query = '<some query>'
const options = {}
// all the initialization steps are done here
const runQuery = JSONPath(query, options)
const object = {...}
const result = runQuery(object)
if the api worked like described, theres a lot of steps we can push onto to the initialization. Here are a few:
new JSONPath
- all path parsing (though the
JSONPath.toPathArray(expr)
step is already cached) vm.createScript(code)
instead ofvm.runInContext({ code })
I havent dug too deep into the code, so it may require redesign if the JSONPath class stores some state related to the json
input. Is this an interesting idea to anyone?