Add generic scope support for expressions.#106
Add generic scope support for expressions.#106movitto wants to merge 1 commit intodchester:masterfrom
Conversation
Variables and funcations can now be injected into the expression
scope like so:
jsonpath.scope({foo:'bar',parseInt:parseInt})
Thus the client can incorporate builtin or custom methods in
jsonpath expressions:
$..[?(parseInt(@.Amount) > 0)]
|
I'd say jsonpath should focus on query, safely and as fast as possible. |
|
@sdawood appreciate the comments. This patch wouldn't preclude fast / safe querying, nor does it serve as a transformation mechanism, rather it allows the developer to use custom helper / utility methods during the query process. The primary use case we had when developing this patch was to query JSON transactions as returned from rippled (https://github.com/ripple/rippled) which stores all floating point values as strings (so as to avoid platform-specific discrepancies with floating point representation). This patch would allow the developer to query this json for float values which match specified numerical conditions. Otherwise the dev would need to run a first pass using jsonpath, then do a second round of querying using some other custom logic. |
|
See, our discussion and comparing problem scopes, one-query -> jsonpath language is specified. @movitto, Great problem statement and enough intuition to start a good conversation amongst the json consumer community 😎 |
|
Thanks for this PR. With it, I was able to make partial matches easily: |
Hey thanks for the awesome library. I'm sending a PR adding functionality where variables and functions can now be injected into the expression scope like so:
jsonpath.scope({foo:'bar',parseInt:parseInt})
This is so the client can inject custom variables and functions to be used when evaluating expressions like so:
$..[?(parseInt(@.Amount) > 0)]