hugo/content/en/functions/transform.Unmarshal.md
Bjørn Erik Pedersen b9bd35d72e Squashed 'docs/' content from commit fdea5430f
git-subtree-dir: docs
git-subtree-split: fdea5430f89dfd849d39212abdf5ace0a4763e5a
2019-10-21 10:22:28 +02: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 accepts 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 used 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" ";") }}