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 supported delimiters, using the provided environment as context. Multiple (different) supported delimiters can be used within a single template. 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. For example, an expression evaluating to true will result in a bool, but quote(true) will result in a string. This behavior should be intuitive to anyone familiar with YAML.
func EvaluateTemplate ¶
EvaluateTemplate evaluates a single template string with the provided environment. A single template string can contain multiple expressions offset by any of the supported delimiters.
Types ¶
This section is empty.