Data Conversion

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 #

  • DATA
  • fromData
  • fromDATA

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 #

  • JSON
  • fromJson
  • fromJSON

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 #

  • toHCL

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 #

  • toJSON

toPrettyHcl #

func toPrettyHcl(value interface{}) string
Converts the supplied value to pretty HCL representation.

Aliases #

  • toPrettyHCL

toPrettyJson #

func toPrettyJson(value interface{}) string
Converts the supplied value to pretty JSON representation.

Aliases #

  • toPrettyJSON

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 #

  • toQuotedHCL

toQuotedJson #

func toQuotedJson(value interface{}) string
Converts the supplied value to compact quoted JSON representation.

Aliases #

  • toQuotedJSON

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 #

  • toYAML

yaml #

func yaml(yaml string) interface{}
Converts the supplied yaml string into data structure (Go spec).

Aliases #

  • YAML
  • fromYaml
  • fromYAML

Examples #

Razor:    @yaml(`foo: bar`).foo
Template: {{ (yaml (`foo: bar`)).foo }}
Result:   bar