triggers: Support JSONPath syntax for variable extraction in TriggerBindings
Expected Behavior
A user should intuitively be able to specify a body parameter to point to a piece of data in their HTTP request JSON body.
Actual Behavior
Currently, the Triggers project is using the gjson library because it makes it easy for us to search the JSON for a specified path. However, gjson does not use the conventional JSONPath syntax, instead it has its own GJSON path syntax. Since the gjson path syntax is different from the JSONPath syntax, it can be unintuitive, and Triggers does not have any documentation linking to an explanation of this syntax.
Furthermore, the bodyPathVarRegex limits the user to a subset of the gjson syntax.
Additional Info
This concern originated in our Slack channel here.
I hope that the following work will come from this issue:
Decide whether to keep the gjson path syntax, or switch to JSONPath
- If we decide to keep the gjson library and the gjson path syntax
- add Triggers documentation linking to the gjson path syntax page
- update the
bodyPathVarRegexto accept all valid gjson path syntax - update/add tests for examples using gjson path syntax
- If we decide to use JSONPath syntax
- find a library that we can substitute for gjson (or use with gjson?)
- update code & tests to use the JSONPath syntax
- add Triggers documentation linking to an explanation of the JSONPath syntax
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 2
- Comments: 15 (11 by maintainers)
Commits related to this issue
- Adds functions to support JSONPath In #178 we decided to support JSONPath syntax for expressions in TriggerBindings. This commit adds functions to support JSONPath using the `k8s.io/client-go/util/js... — committed to dibyom/triggers by dibyom 5 years ago
- Support JSONPath in TriggerBindings This commit switches the expression syntax in TriggerBindings from GJson to JSONPath. Fixes #178 — committed to dibyom/triggers by dibyom 5 years ago
- Adds functions to support JSONPath In #178 we decided to support JSONPath syntax for expressions in TriggerBindings. This commit adds functions to support JSONPath using the `k8s.io/client-go/util/js... — committed to dibyom/triggers by dibyom 5 years ago
- Support JSONPath in TriggerBindings This commit switches the expression syntax in TriggerBindings from GJson to JSONPath. Fixes #178 — committed to dibyom/triggers by dibyom 5 years ago
- Adds functions to support JSONPath In #178 we decided to support JSONPath syntax for expressions in TriggerBindings. This commit adds functions to support JSONPath using the `k8s.io/client-go/util/js... — committed to dibyom/triggers by dibyom 5 years ago
- Support JSONPath in TriggerBindings This commit switches the expression syntax in TriggerBindings from GJson to JSONPath. Fixes #178 — committed to dibyom/triggers by dibyom 5 years ago
- Support JSONPath in TriggerBindings This commit switches the expression syntax in TriggerBindings from GJson to JSONPath. Fixes #178 — committed to dibyom/triggers by dibyom 5 years ago
- Support JSONPath in TriggerBindings This commit switches the expression syntax in TriggerBindings from GJson to JSONPath. Fixes #178 Signed-off-by: Dibyo Mukherjee <dibyo@google.com> — committed to dibyom/triggers by dibyom 5 years ago
- Support JSONPath in TriggerBindings This commit switches the expression syntax in TriggerBindings from GJson to JSONPath. Fixes #178 Signed-off-by: Dibyo Mukherjee <dibyo@google.com> — committed to dibyom/triggers by dibyom 5 years ago
- Adds functions to support JSONPath In #178 we decided to support JSONPath syntax for expressions in TriggerBindings. This commit adds functions to support JSONPath using the `k8s.io/client-go/util/js... — committed to tektoncd/triggers by dibyom 5 years ago
I think it’d be best to stick to one syntax (and one library) to avoid confusion & more convoluted code.
From the discussion here, it sounds like JSONPath would be best for us to use. It seems like whoever picks up this issue to implement JSONPath should probably check out the https://godoc.org/k8s.io/client-go/util/jsonpath library that @dibyom mentioned, or find another library to replace the gjson library in our Triggers code 👍
Good question. What I’m thinking (using Option 2 from above) is using the
$()to differentiate. So, a user would do the following:$(body.head_commit.id)- JSONPath value replacedbody.head_commit.id- raw string.Definitely option 2 or 3. I don’t particularly like curly braces because it looks like a template, but it isn’t? To keep consistency with stuff like
$(uid), I suppose I vote option 2.Based on the WG discussion today, we agreed to move forward with replacing Gjson with JSONPath for event variable interpolation in trigger bindings.