Data Conversion
#
data
#
func data(data interface{}, context ...interface{}) interface{}
Tries to parse the given input string as a data structure. This
function supports JSON, HCL and YAML. If the context argument is
omitted, the default context is used.
Note that this function attempts to template the given input string.
This means that if the input string contains gotemplate expressions,
those will be evaluated. This behavior is deprecated and will be
removed in future versions of gotemplate. If you are using this
behavior, please use `@data(include("..."))` or `{{ data (include
"...") }` to future proof your code.
Aliases
#
Examples
#
Razor: @data(`{"foo": "bar"}`).foo
Template: {{ (data (`{"foo": "bar"}`)).foo }}
Result: bar
Razor: @data(`foo: bar`).foo
Template: {{ (data (`foo: bar`)).foo }}
Result: bar
Razor: @data(`foo = "bar"`).foo
Template: {{ (data (`foo = "bar"`)).foo }}
Result: bar
hcl
#
func hcl(hcl string) interface{}
Converts the supplied hcl string into data structure (Go spec).
Aliases
#
- HCL
- fromHcl
- fromHCL
- tfvars
- fromTFVars
- TFVARS
- fromTFVARS
Examples
#
Razor: @hcl(`foo = "bar"`).foo
Template: {{ (hcl (`foo = "bar"`)).foo }}
Result: bar
json
#
func json(json string) interface{}
Converts the supplied json string into data structure (Go spec).
Aliases
#
Examples
#
Razor: @json(`{"foo": "bar"}`).foo
Template: {{ (json (`{"foo": "bar"}`)).foo }}
Result: bar
toBash
#
func toBash(value interface{}) string
Converts the supplied value to bash compatible representation.
toHcl
#
func toHcl(value interface{}) string
Converts the supplied value to compact HCL representation.
Aliases
#
toInternalHcl
#
func toInternalHcl(value interface{}) string
Converts the supplied value to compact HCL representation used inside
outer HCL definition.
Aliases
#
- toInternalHCL
- toIHCL
- toIHcl
toJson
#
func toJson(value interface{}) string
Converts the supplied value to compact JSON representation.
Aliases
#
toPrettyHcl
#
func toPrettyHcl(value interface{}) string
Converts the supplied value to pretty HCL representation.
Aliases
#
toPrettyJson
#
func toPrettyJson(value interface{}) string
Converts the supplied value to pretty JSON representation.
Aliases
#
toPrettyTFVars
#
func toPrettyTFVars(value interface{}) string
Converts the supplied value to pretty HCL representation (without
multiple map declarations).
toQuotedHcl
#
func toQuotedHcl(value interface{}) string
Converts the supplied value to compact quoted HCL representation.
Aliases
#
toQuotedJson
#
func toQuotedJson(value interface{}) string
Converts the supplied value to compact quoted JSON representation.
Aliases
#
toQuotedTFVars
#
func toQuotedTFVars(value interface{}) string
Converts the supplied value to compact HCL representation (without
multiple map declarations).
toTFVars
#
func toTFVars(value interface{}) string
Converts the supplied value to compact HCL representation (without
multiple map declarations).
toYaml
#
func toYaml(value interface{}) string
Converts the supplied value to YAML representation.
Aliases
#
yaml
#
func yaml(yaml string) interface{}
Converts the supplied yaml string into data structure (Go spec).
Aliases
#
Examples
#
Razor: @yaml(`foo: bar`).foo
Template: {{ (yaml (`foo: bar`)).foo }}
Result: bar