Debian Codegraph @

docs/content/en/functions/transform/Remarshal.md

raw
1 ---
2 title: transform.Remarshal
3 description: Returns a string of serialized data in the specified format, marshaled from a string of serialized data or a map.
4 categories: []
5 keywords: []
6 params:
7 functions_and_methods:
8 aliases: []
9 returnType: string
10 signatures: [transform.Remarshal FORMAT INPUT]
11 aliases: [/functions/transform.remarshal]
12 ---
13
14 ## Usage
15
16 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.
17
18 > [!NOTE]
19 > This function is primarily a helper for Hugo's documentation, used to convert configuration and front matter examples to JSON, TOML, and YAML.
20 >
21 > This is not a general purpose converter, and may change without notice if required for Hugo's documentation site.
22
23 ## Examples
24
25 The following examples convert data from one serialized format to another.
26
27 ### TOML to JSON
28
29 This example converts a string of TOML to JSON:
30
31 ```go-html-template
32 {{ $s := `
33 baseURL = 'https://example.org/'
34 locale = 'en-US'
35 title = 'ABC Widgets'
36 `}}
37 <pre>{{ transform.Remarshal "json" $s }}</pre>
38 ```
39
40 Resulting HTML:
41
42 ```html
43 <pre>{
44 &#34;baseURL&#34;: &#34;https://example.org/&#34;,
45 &#34;locale&#34;: &#34;en-US&#34;,
46 &#34;title&#34;: &#34;ABC Widgets&#34;
47 }
48 </pre>
49 ```
50
51 Rendered in browser:
52
53 ```text
54 {
55 "baseURL": "https://example.org/",
56 "locale": "en-US",
57 "title": "ABC Widgets"
58 }
59 ```
60
61 ### Map to YAML
62
63 This example converts a map to YAML:
64
65 ```go-html-template
66 {{ $m := dict
67 "a" "Hugo rocks!"
68 "b" (dict "question" "What is 6x7?" "answer" 42)
69 "c" (slice "foo" "bar")
70 }}
71 <pre>{{ transform.Remarshal "yaml" $m }}</pre>
72 ```
73
74 Resulting HTML:
75
76 ```html
77 <pre>a: Hugo rocks!
78 b:
79 answer: 42
80 question: What is 6x7?
81 c:
82 - foo
83 - bar
84 </pre>
85 ```
86
87 Rendered in browser:
88
89 ```text
90 a: Hugo rocks!
91 b:
92 answer: 42
93 question: What is 6x7?
94 c:
95 - foo
96 - bar
97 ```