transform.Remarshal
Syntax
transform.Remarshal FORMAT INPUT
Returns
string
格式必须为json
、toml
、yaml
或xml
之一。如果输入是一个序列化数据字符串,则它必须是有效的JSON、TOML、YAML或XML格式。
- 示例1
- 将一个TOML字符串转换为JSON。
{{ $s := `
baseURL = 'https://example.org/'
languageCode = 'en-US'
title = 'ABC Widgets'
`}}
<pre>{{ transform.Remarshal "json" $s }}</pre>
生成的HTML:
<pre>{
"baseURL": "https://example.org/",
"languageCode": "en-US",
"title": "ABC Widgets"
}
</pre>
在浏览器中显示的结果:
{
"baseURL": "https://example.org/",
"languageCode": "en-US",
"title": "ABC Widgets"
}
- 示例2
- 将一个映射转换为YAML。
{{ $m := dict
"a" "Hugo rocks!"
"b" (dict "question" "What is 6x7?" "answer" 42)
"c" (slice "foo" "bar")
}}
<pre>{{ transform.Remarshal "yaml" $m }}</pre>
生成的HTML:
<pre>a: Hugo rocks!
b:
answer: 42
question: What is 6x7?
c:
- foo
- bar
</pre>
在浏览器中显示的结果:
a: Hugo rocks!
b:
answer: 42
question: What is 6x7?
c:
- foo
- bar