hugo/content/en/functions/transform.Unmarshal.md
Bjørn Erik Pedersen 978856e2ad Squashed 'docs/' changes from bd91d1cfd..785e375f5
785e375f5 Change 'my-another-post' to 'my-other-post'
ba9a69d25 Update reflect.IsSlice.md
806344258 Update reflect.IsMap.md
757c0dafa Update index.md
d3f20a2d5 Update index.md
9952e72a0 Formatting
70458ccf2 Formatting
7e0dd3969 Merge branch 'config-dir'
06a5c11fc Release 0.53
01c00229f releaser: Prepare repository for 0.54-DEV
29b223f78 releaser: Add release notes to /docs for release of 0.53
4f61d1194 releaser: Bump versions for release of 0.53
320a0ac68 Refactor config below /config
ec16b611e docs: Adjust CSV example
cecf97dfc Rename CSV option from comma to delimiter
18d06df58 docs: Document transform.Unmarshal
fdace78b5 docs: Regenerate CLI docs
b8f84ac59 hugolib: Add .Name as a shortcode variable
6612dd1b8 Merge commit '5a83bf314f4c0ce1d61341e0a1df21c9998e8154'
9b211089f docs: Regenerate CLI docs
9af46af3c Merge commit 'eb16165694f868d73e57b6aed5c26ba5e98229de'
12f46f356 tpl: Add reflect namespace

git-subtree-dir: docs
git-subtree-split: 785e375f577394c6f782ef51796e2efe88d52cbb
2018-12-26 10:27:12 +01:00

1.3 KiB

title description date categories menu keywords signature hugoversion aliases
transform.Unmarshal `transform.Unmarshal` (alias `unmarshal`) parses the input and converts it into a map or an array. Supported formats are JSON, TOML, YAML and CSV. 2018-12-23
functions
docs
parent
functions
RESOURCE or STRING | transform.Unmarshal [OPTIONS]
0.53

The function accept either a Resource created in Hugo Pipes or via Page Bundles, or simply a string. The two examples below will produce the same map:

{{ $greetings := "hello = \"Hello Hugo\"" | transform.Unmarshal }}`
{{ $greetings := "hello = \"Hello Hugo\"" | resources.FromString "data/greetings.toml" | transform.Unmarshal }}

In both the above examples, you get a map you can work with:

{{ $greetings.hello }}

The above prints Hello Hugo.

CSV Options

Unmarshal with CSV as input has some options you can set:

delimiter
The delimiter used, default is ,
comment
The comment character ued in the CSV. If set, lines beginning with the comment character without preceding whitespace are ignored.:

Example:

{{ $csv := "a;b;c" | transform.Unmarshal (dict "delimiter" ";") }}