transform.Remarshal
Syntax
transform.Remarshal FORMAT INPUT ⟼ string
The FORMAT must be one of json
, toml
, yaml
, or xml
. If the INPUT is a string of serialized data, it must be valid JSON, TOML, YAML, or XML.
- Example 1
- Convert a string of TOML to JSON.
{{ $s := `
baseURL = 'https://example.org/'
languageCode = 'en-US'
title = 'ABC Widgets'
`}}
<pre>{{ transform.Remarshal "json" $s }}</pre>
Resulting HTML:
<pre>{
"baseURL": "https://example.org/",
"languageCode": "en-US",
"title": "ABC Widgets"
}
</pre>
Rendered in browser:
{
"baseURL": "https://example.org/",
"languageCode": "en-US",
"title": "ABC Widgets"
}
- Example 2
- Convert a map to YAML.
{{ $m := dict
"a" "Hugo rocks!"
"b" (dict "question" "What is 6x7?" "answer" 42)
"c" (slice "foo" "bar")
}}
<pre>{{ transform.Remarshal "yaml" $m }}</pre>
Resulting HTML:
<pre>a: Hugo rocks!
b:
answer: 42
question: What is 6x7?
c:
- foo
- bar
</pre>
Rendered in browser:
a: Hugo rocks!
b:
answer: 42
question: What is 6x7?
c:
- foo
- bar