Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EvaluateJSONTemplate ¶
func EvaluateJSONTemplate(jsonBytes []byte, env map[string]any, exprOpts ...expr.Option) ([]byte, error)
EvaluateJSONTemplate evaluates a JSON byte slice, which is presumed to be a template containing expr-lang expressions offset by ${{ and }}, using the provided environment as context. The evaluated JSON is returned as a new byte slice, ready for unmarshaling.
Only expressions contained within values are evaluated. i.e. Any expressions within keys are NOT evaluated.
Since the template itself must be valid JSON, all expressions MUST be enclosed in quotes.
If, after evaluating all expressions in a single value (multiples are permitted), the result can be parsed as a bool, float64, or other valid non-string JSON, it will be treated as such. This ensures the possibility of expressions being used to construct any valid JSON value, despite the fact that expressions must, themselves, be contained within a string value. This does mean that for expressions which may evaluate as something resembling a valid non-string JSON value, the user must take care to ensure that the expression evaluates to a string enclosed in quotes. e.g. ${{ true }} will evaluated as a bool, but ${{ quote(true) }} will be evaluated as a string. This behavior should be intuitive to anyone familiar with YAML.
Types ¶
This section is empty.