ietf-wg-jsonpath / draft-ietf-jsonpath-base

Development of a JSONPath internet draft
https://ietf-wg-jsonpath.github.io/draft-ietf-jsonpath-base/
Other
58 stars 20 forks source link

Define syntactic validity of function expressions #330

Closed glyn closed 1 year ago

glyn commented 1 year ago

This PR also addresses https://github.com/ietf-wg-jsonpath/draft-ietf-jsonpath-base/issues/327.

gregsdennis commented 1 year ago

My JsonPath.Net library now implements everything in the spec, including this PR. (It also supports math operations in expressions, which isn't part of the spec (yet).)

The function infrastructure was a struggle (mostly because I'm in a strongly typed language, I suspect), but once implemented, creating the functions themselves and registering them so that they can be parsed was easy!

With my lib, the user would implement a "function definition" interface which exposes the name, the range of parameters expected (min/max), and the logic for the function itself (which follows a pattern defined in my lib). Once an instance of their definition is registered, it's available to be parsed. The parsing logic handles validating that the function receives the correct number of parameters, too, so if you send length() seven arguments, it'll fail to parse.